0

I'm trying to hide the empty categories (with no posts associated) from a list in an archive page. I'm using hide_empty as suggested on Wordpress codex but it's not working, the code outputs all categories:

<ul class="filter-menu">
  <?php $cat = get_query_var('cat');
    foreach(get_categories('parent=0&hide_empty=1') as $category) {
      echo '<li><a href="#" data-filter=".'. $category->slug.'" >' . $category->name.'</a></li>';
    }
  ?>
</ul>

Any idea what I'm doing wrong or how could I modify the code to make it work?

1
  • 2
    Are you sure categories you think are empty are indeed empty? Go to Posts > Categories in the admin and check that the post count column is 0 for those in question. Commented May 2, 2016 at 17:03

1 Answer 1

-3

Try this hide_empty=1 it should be hide_empty=0

2
  • 1
    Please explain why this would help
    – cjbj
    Commented Oct 10, 2016 at 9:08
  • no, there should be 1, OP does it correctly. Just something other problem.
    – T.Todua
    Commented Oct 10, 2016 at 10:46

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.