Oh, I feel your pain! We had the exact same thing with dd at that age. She didn't potty train until just before her third birthday but then it was really quick, and while she was just getting over the constipation, finally.
Movicol worked but what made the difference was a parent with experience (and on the advice she'd received from a paediatrician) telling us to treat as long as she'd been affected for, and not to reduce the dose of movicol too fast. It's a powerful laxative, and basically if they can hold anything while on it, they're still withholding (applies only if withholding is your dds issue and not true constipation). Whenever ours did a poo in her sleep, we cut it by half a packet.
Weirdly, potty training helped because she got rewards. And (warning, detail!) I think they do a more complete motion on the potty than in nappies, especially if they otherwise like to stand to go.
All the other tricky stuff for 2 year olds, like plenty of fibre and fluids, does help, but more important I think is no sudden dietary changes. Going on holiday and her not having all her usual homemade food I think is what a started all our problems. Later her diet wasn't as good as it had been but as long as it was regular, she was okay.
There's a great book, for older kids really but as mine got to 3 it started to work, Constipation, Withholding and Your Child, by Anthony Cohn (a doctor). It gives you a story to tell about Mr Poo getting cross and kicking their tummies if he doesn't get to come out when he wants. Dd still occasionally mentions it, at nearly 5, usually a sign that she needs extra broccoli and water!
Apple & pear juice mixed with prune juice and water helped too. Also dried apricots and lots of fluids if you can get her to take them.
Good luck, I remember how horrible it could be.