How to count the number of posts in category

Home / WordPress / How to count the number of posts in category

If you want to count the number of posts in any category, there are number of ways to perform this check. Here are some of my ideas that worked.

This one uses PHP count function. You can always set a different condition. Mine is checking if there are more than 10 posts in category with ID 50.

Somewhere inside WordPress core (category.php template to be specific), you can also find the category_count function:

Which seems to be doing the same.