4 year old poops himself

My 4 year old has been potty trained for a long time but for the past few months he has been popping himself. He would go to his closest and try to poop until I realized and make him get on the toilet . He will have poop stuck in his but sometimes so i blamed it on constipation . But then there’s times where it’ll be balls of poop in the floor . Then I started giving him Miriam and he will poop on himself with that too . I’m not understanding cause he was doing good with potty training. and even after he mastered the potty training he rarely had accidents. And now it seems like he’s just going backwards . He barely pees on himself but there is times where he does .