Support » Everything else WordPress » Overlooked hide_empty=0 when displaying sub categories?

  • Hi!
    I just had a day of search and couldn’t figure out why a sub category menu didn’t work on my test site. There are many places, including codex, where you can find code that should work. Problem is, you can’t just make the sub category posts, catgorize and think you’re good without adding hide_empty=0 in your query IF THE POSTS CONTAIN NO CONTENT. It will fail and you will get the WP error message “No categories”. I hope this makes some sense to you. Here is code from this post that works for my testing without actual content in my sub category posts. Just add the “hide_empty=0”:

    <?php if(!in_the_loop()) global $post;
    $catNow = get_cat_ID(single_cat_title($post->ID,'',false)); $output = '';
    if($catNow && $catNow !== 0) $output .= wp_list_categories('hide_empty=0&echo=0&child_of='.$catNow.'&title_li=');
    echo $output; ?>
  • The topic ‘Overlooked hide_empty=0 when displaying sub categories?’ is closed to new replies.