Post count in a category

DescriptionWordpress snippet by - 07/18/10

This retrieves the number of posts in category 5. This wordpress function is very handy. Show how many posts you have in a specific category. If you have parent categories you can use their id to get parent category post totals.

Tags

<?php
$chosen_id = 5;
$thisCat = get_category($chosen_id);
echo $thisCat->count;
?>
  • Share
Authored by: Adam J Nowak
http://hyperspatial.com

3 Responses to “Post count in a category”

  1. Thank you so much for posting this code. I've been searching an querying others for days looking for code that shows the count total only so I could insert it next to text I'd formatted myself. Found code that showed the total without the category name, but it still displayed the title, 'Category'. And on... But finally, I found your page. Bless you for opening up a window of coding opportunity to me I almost thought was nailed shut.

    Best,
    VC

  2. It doesn't show the total number of posts under parent category...
    just the ones straight under that category...

    any solution?

    Thank's!

Comments and Feedback