Hide empty categories from get_categories

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>';

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



  1. Shankar
    1 Votes

    Try this hide_empty=1 it should be hide_empty=0

Please signup or login to answer this question.

Signup for an account and start participating in our site today!

Social Signup

You can also login with your Facebook, Twitter or Linkedin account

Log in with Facebook