There isn't too much info here to fully know. Some kids that are constipated have this issue. And you can actually go to the bathroom every day and still be constipated. If this happens, a child feels like they have to go often but don't and then when they do, they miss the signal that THIS time it is for real. It also can be a bit painful and then they avoid it. Encropsis can also happen and then a child has 'leakage' which looks a bit like a bowel movement but is a bit different.
So, I guess it would be helpful if you provided more details.
My son had accidents of wetting his pants this past Fall for about a week due to stress of adjusting to all day first grade.
Because he is upset by something, does he do it at school aswell as home ?