Sounds like you and I have/had very similar situations! A little history...my daughter has been potty trained since 18 months, rarely had accidents - she just really got the process. Then, around last Christmas (the month before she turned 2) she struggled with constipation. We ended up taking her to the doctor, b/c it seemed everything we did just backfired. We put her on a high fiber diet and lots of water. They put her on a high fiber diet and low dose of a laxative. Basically, this is what helped us get back on track:
*don't punish or react negatively or show frustration to pooping in pants (it's VERY hard, b/c no one wants to clean poop off of underwear day in and day out). i just calmly told her that when she feels that sensation she has to tell me and go on the toilet, it's yucky to go poopy in your pants, etc.
*explain that the new foods (and laxative, if you go that route) will help pooping not hurt anymore.
* get SUPER EXCITED for successes
* the doctor recommended retraining her by putting her on the potty after every meal. This is what I think started to get her back on track, b/c we talked a lot about how everyone has to poop and lots of people do it after they eat, etc. etc.
After awhile I think she just began to forget about how much it used to hurt and realized it was a normal routine.
I know this seems like common sense, but I thought I'd share because after awhile I got so frustrated not knowing what was the right tactic. I found that you just need to be consistent and they'll start to see it as routine and begin going on the toilet again.
High Fiber Foods:
* Fiber one Yogurt
* Naked and Bolthouse juices both make a juice that is high in fiber...it's the purple one.
* Fiber one granola bars (target sells their brand of these)
* Most fruits
* A lot of breads have a high fiber option available.
* Basically, I switched all her "usuals" to high fiber alternatives (raisin bran instead of rice crispies, etc.)
**The doctor also advised us to limit milk to three servings a day, as milk can be constipating.
Hope this helps!