I am trying to get the post count for a term and it's child terms. I tried it with pad_count=> true but this seems to have no effect.

My term stucture is like the following:

- term 1: 10 posts
- term 2: 1 post
  -- subterm 1: 4 posts
  -- subterm 2: 12 posts
- term 3: 4 posts

This is my code:

$args = array(
  'pad_counts' => true
$terms = get_terms('category', $args);
foreach($terms as $term) {
  var_dump( $term->count );

For all the terms without children this works just fine, but for the "term 2", I want to get the counts of itself and it's children combined. In my example this would be 17. The code only gives me 1, though.

Any Tips?

1 Answer 1


I don't know why that code didn't work for you. I copy that code and it work exactly as I expected. You should double check your case, did you unset $args variable before, or you can use another name ($agrs2 for example).

Another problem in you question is: if pad_counts doesn't work, you will get 1 not 3.

  • oh you are right, I ment 1 of course. I will double check my code and report back.
    – rassoh
    Nov 11, 2015 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.