Grandparents might get rights to visitation if they had acted in the place of a parent - say the child lived with the grandparents for some period of time - and that would fall under "the best interest of the child."
I'm sure there's exceptions, but that's generally the way it works.
I didn't mean in reference to custody but visitations. Probably varies by state. But at least in some states if the parents are divorced or one dies, the grandparents have visitation rights.