In order to file an action for custody in Pennsylvania, a person must first have "standing" to do so. Standing is just another way of saying that a person is allowed, as a matter of law, to file for what they are asking the court to do. For custody cases, there a several different ways a person can have standing.
To file for any form of physical or legal custody, a natural parent of the child always has standing. A person who is in loco parentis to the child also has standing. This phrase means "in the place of a parent" and refers to a situation where another person has been caring for the child and performing parental duties, even though he or she is not a biological parent.
A grandparent who is not in loco parentis, may be able to file for any form of custody if several conditions are met. The relationship with the child had to begin with either the consent of a parent or a court order. The grandparent must also be willing to assume responsibility for the child. In addition to the first two conditions, one of the following conditions must also be met: 1) the child has been adjudicated dependant by the court; 2) the child is substantially at risk from abuse, neglect, drug or alcohol abuse or incapacity; or 3) the child has lived with the grandparent exclusively for a period of one year with the exception of short periods away, and has been removed from the home by one of the parents within six months of the filing date.