I'm working on a pictures gallery, where there is no 'regular' post, only images with several custom taxonomies, some of them being hierarchical.

I use wp_list_categories() to display hierarchical lists of terms and that works fine provided I set the hide_empty parameter to 0. However, I would like to display only terms that have pictures, or whose descendants have pictures. But I can't find a way to use hierarchical instead of hide_empty, probably because the function looks for terms attached to regular posts.

Is there a way to change its behaviour and make it look for post-type='attachment' or whatever, so I could list only terms related to published pictures?

Thanks for helping.

1 Answer 1


When you register your taxonomy, set the update_count_callback argument to _update_generic_term_count. This will count all objects associated to taxonomy terms so you don't need to use hide_empty.

$args = array(
    // your other taxonomy arguments here
    'update_count_callback' => '_update_generic_term_count'
register_taxonomy( 'your-taxonomy', array( 'attachment' ), $args );
  • Is this supposed to work with the wp_list_categories() function too? Because I can't see any difference with the _update_generic_term_count parameter. It's either hide_empty set to false and I get everything; or hide_empty is true and the only children categories I get are those containing media attached to some post (the home page in fact, as it is the only one that uses attached media). And by the way, the pad_counts parameter doesn't seem to work either.
    – tosca
    May 19, 2014 at 6:50
  • If you just changed that parameter then term counts are still wrong since you've associated the attachments before making that change. You either need to manually update the term count field or re-add terms to attachments to fix the count.
    – Milo
    May 19, 2014 at 13:38
  • Thanks. That seems to have done it, though I'm a bit surprised I had only to remove/add each term from one media only to get the counter right.
    – tosca
    May 20, 2014 at 8:44

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.