0

By default the Count column shows the number of category's own posts only. Instead, I want to see the total number of records taking into account posts in child categories.

screenshot

I know that the get_terms function has the pad_counts parameter:

Whether to pad the quantity of a term's children in the quantity of each term's "count" object variable. Default false.

So I suppose that I can change the same parameter for some query using some hook. But how to find them? Is my guess correct?

  • So in the screenshot above you expect the parent category count to be 2 not 0? – Tom J Nowell Jun 29 '17 at 18:02
  • Yes, I would like that. – Gleb Kemarsky Jun 29 '17 at 18:09
  • Have you considered removing that column and adding your own Count column in? – Tom J Nowell Jun 29 '17 at 18:14
  • I can do it. But I hope I can correct someone else's work instead of redoing it. – Gleb Kemarsky Jun 29 '17 at 18:18
0

You can change an array of get_terms() arguments with two filters:

  1. get_terms_defaults filters the terms query default arguments;

  2. get_terms_args filters the terms query passed arguments.

For example, this code will change the default value for the pad_counts parameter for all queries related to categories and called from the administrative part of the site.

add_filter( 'get_terms_defaults', 'custom_get_terms_defaults', 10, 2 );
function custom_get_terms_defaults( $defaults, $taxonomies ) {
  if ( is_admin() && in_array( 'category', $taxonomies ) ) {
    $defaults['pad_counts'] = true;
  }
  return $defaults;
}

result

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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