We are currently coming out the other side of a very similar situation. My 3 year old was constipated and got an anal fissure - a small tear in the anus, which would sometimes bleed and was very painful, this caused her to be frightened of pooing as it would be so painful. As a result of this she started fighting the urge to poo and holding it in, which lead to her becoming more and more constipated (this is all the Doctor's theory, as we can't actually prove this happened). I tried all of the usual dietary advice (linseeds, kiwifruit, prunes, prune juice etc, etc) with no success, so took her to the doctor. The doctor prescribed lactulose (a stool softener) and a cream to ease the pain of the fissure. This didn't work and she was put on a bigger and bigger dose, she was also prescribed suppositories (which was the worst thing in the world as it traumatised her further in an already traumatic situation) neither of these worked. We are now 3 and a half months in, and we see the doctor weekly. We are at (at I quote) the last step before hospitalisation, thankfully it seems to be working. DD is now on Movicol (another stool softener) with an increasing dose (ie day one is 1 sachet, days 2 and 3 is 2 sachets, day 4 and 5 is 4 sachets and day 6 is 8 sachets - the doctor said that 'no one has made it to day 6 without going')
The problem with DD is that her bowel had become impacted and so it was just about impossible for her to push the poo out even if she had been trying to. Now she has the runs so can't hold it in. We have to keep seeing the doctor weekly until she has started pooing again, but he said that she will need to be on medication for months as if we stop giving it to her too soon it will start again almost immediately.
It is a horrible situation and has railroaded toilet training completely for us. It is very stressful and just awful really.
I hope that my story has helped in some way.
Just edited to add - I also asked about food allergies or intolerances and apparently in most cases of that the person gets the runs so it is unlikely.
Ask the doctor if they can feel her tummy as you can generally feel if they are constipated as it is hard and uncomfortable. Also you can tell if they are impacted as (eventually) there will be poo sitting right at the opening of the bottom but it doesn't come out, and liquid poo runs down the side so the nappy is pretty much always poo stained (that is what the doctor asked us - is the nappy stained but there has been no bowel movement).