WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom taxonomy(the taxonomy is types) that is basically a selector that tells WordPress which section of the site to place the new post.

So for example

  1. I create a new post and select Lifestyle from the custom taxonomy list.
  2. Then I would select a category to place the post under, for example Healthy

I am trying to list the categories of Lifestyle in a custom menu format but only if posts exist under the taxonomy type and category selected.

What I am getting is a full list of categories but not filtered by taxonomy type.

Can anyone see where I have gone wrong?

  'types' => 'Lifestyle',
  'orderby' => 'name',
  'order' => 'ASC',
  'hide_empty' => 1
  foreach($categories as $category) {
    if ($category->count > 0){
    echo '<li class="'.$category->slug.'"><a href="?category=' . $category->slug . '">'.$category->name.' / '.$category->count.'</a></li>';

Thanks so much in advnce! -d

share|improve this question

get_categories() only lists categories, so you shouldn't be seeing any terms from the custom taxonomy. What you want to use is get_terms() which takes a taxonomy as an argument. As you can read about in this answer, get_terms() is actually used by get_categories(), it just prefills the "taxonomy" argument with "category."

If you swap in get_terms() and add the name of your custom taxonomy, your code looks like it should work. The only other thing you may be able to change is your if statement checking the category count. If you're already doing 'hide_empty' => 1 you shouldn't need that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.