we had the same issues before my youngest could speak - started as an infant and continued until this past summer - and after a number of dietary changes, our Ped suggested Miralax. I don't usually like medications, but our Ped assured me it isn't retained in their body. Miralax is flushed out; it just helps the body to move the bowel movements along.
My daughter's weren't hard but for a few times. She just constantly cried while passing them and eventually stopped having them, thus training her body to constipate itself.
We did 1/4 of the dosage on the bottle, mixed it in with her milk. She never noticed a taste difference. We started it once a day and about 2 weeks later we were only doing it once every 3 days, so I just stopped it and she was fine.
Good luck! I know it's hard to see them in pain. Hopefully you find what works!