I refer to this post where I have just taken my code from: How to display a listing template of a certain taxonomy?

I am trying to create a page template that will list all categories in "servicecats" taxonomy which is linked to the custom post-type "Services".

In the page template I have used the code taken from the link above:


        $taxonomy     = 'servicecats';
        $orderby      = 'name'; 
        $show_count   = 0;      // 1 for yes, 0 for no
        $pad_counts   = 0;      // 1 for yes, 0 for no
        $hierarchical = 1;      // 1 for yes, 0 for no
        $title        = '';

        $args = array(
          'taxonomy'     => $taxonomy,
          'orderby'      => $orderby,
          'show_count'   => $show_count,
          'pad_counts'   => $pad_counts,
          'hierarchical' => $hierarchical,
          'title_li'     => $title

<?php wp_list_categories( $args ); ?>

When I view the page, it just says "No categories" although I do have 4 set up, the taxonomy and post-type are both hierarchical.

Any suggestions? Thanks


I managed to sort this using:

<?php $category_ids = get_all_category_ids(); ?>
      $args = array(
         'orderby' => 'slug',
         'parent' => 0,
        'taxonomy' => 'servicecats'
      $categories = get_categories( $args );
      foreach ( $categories as $category ) {
         echo '<li><img src=""/><a href="' . get_category_link( $category->term_id ) . '" rel="bookmark">' . $category->name . '' . '' . $category->description . '</a></li>';

Would still like to know how to also show the empty categories though if anyone could offer advice on this?

  • You should accept your own answer. Please help keeping the site clean of unnecessary open questions :-) – Pieter Goosen Nov 20 '14 at 18:43
  • Sorry Pieter, I did try to when I posted but told me I could only accept my own answer after x days and then forgot to come back. – Adrian Nov 20 '14 at 20:39

Just use 'hide_empty' and set it to false as it's true per default.

wp_list_categories( array(
    'hide_empty' => false,
) );

The code in question works and I can only think of two reasons why it fails

  • Wrong taxonomy name supplied

  • The terms assigned to taxonomy is empty

I would suggest that you get wp_list_categories() working as it is faster and less resource intensive than get_categories()

To get empty terms, simply add the hide_empty parameter to your arguments and set it to 0

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.