Both our cats had this, but they had it when we picked them up as kittens (12 wks old). Had a bunch of tests and samples taken. Tried them out on different foods as it was thought they were sensitive to most stuff. Remember them being on this duck and pea stuff which the cats were not impressed with. Vet never pinned down what it was. We settled on Hills Prescription Diet Z/D wet and dry food. The cats were never excited about it but ate it fine. Had them on it for about 3 years. Their stools did sort itself out over a year. About a year ago now we slowly started to introduce other food which they now go nuts for and are completely off the Z/D. No problems with the stools.
I think having them on one type of bland food for a prolonged period of time helped. Also trimming the fur around their butt as the wet poo would catch on their long fur, would help our anxiety about the situation.