When my daughter was young I wanted to be a stay-at-home mom so I operated a family daycare home for many years. As a result I had experience with potty training lots of kids and perhaps some things I learned will be helpful to other parents.
Children become ready for potty training at various ages and trying to teach them to control what they aren't yet able to do only results in frustration for both the children and parents. They must be able to feel when their bladders and bowels are full before they can control their elimination.
I knew quite a few children whose parents started the training before the kids were ready and it took more than a year for them to become trained. On the other hand, one little boy's parents didn't start potty training until he was nearly three years old and he was completely trained in less than a week.
It's also important to communicate exactly what is expected.
One little boy never wet his pants, but would have severe diarrhea in his clothing a couple of times a week. Finally one day he told me through his tears, "I try and try not to go, but it just comes out!" He had misunderstood and thought it was wrong to have a bowel movement at all, and had been holding in his excrement until it liquified. I explained that it wasn't wrong to have a bowel movement as long as it was in the toilet and he never had another 'accident.'
Kids going through stress, which can be anything from a parental divorce, health problems, moving, a new sibling, or even going on a fun vacation, often have setbacks or delays to their training. And a few may have physical health problems that require medical assistance. But, in most cases, if children are physically mature enough and their parents communicate well, they will be completely potty trained (at least during waking hours) by the time they're old enough for preschool.
Potty training isn't easy for either parents or kids, but it really only takes a small part of a lifetime. When frustrated it may help to remember, "This too shall pass." (Pun intended.)