How to get the number of posts in a selected category?

If you are on a category archive you don’t need to query all the posts of the category like Christopher Ross suggested and you can’t use get_the_category() like Max Yudin suggested unless you are already in the loop.

What you can do is simply get the current category object using get_queried_object() which will hold the post count, ex:

$category = get_queried_object();
echo $category->count;

Leave a Comment