Home » Labs » Total Post Count of a Category in WordPress  

Total Post Count of a Category in WordPress

Filed under Labs

Some times you need to display total posts count in each category, on such situation you can use the following set of code into your Word Press theme. For displaying total post count of category you must add the below code into your functions.php.

function wp_get_postcount($id)
$count = 0;
$taxonomy = 'category';
$args = array(
  'child_of' => $id,
$tax_terms = get_terms($taxonomy,$args);
foreach ($tax_terms as $tax_term) {
$count +=$tax_term->count;
return $count;

And you can call above function where ever in your template file as follows.

echo wp_get_postcount(3);
// This will echo total count of postesunder ID 3

Posts you may like: