I have a problem here, I registered a custom post type and I named it 'recipe' then I created a custom taxonomy under the post type, I named it 'recipe category'. Now I want to display the of categories under that custom taxonomy, but unfortunately I have no luck.

I tried this code


$taxonomy = 'recipecategory';
$tax_terms = get_terms($taxonomy);
foreach ($tax_terms as $tax_term) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';

but it displays nothing, what's wrong with my code? did I missed something. Almost forgot to mention, I am using the plugin Custom Post Type UI

  • Does it output empty markup (li,a), or absolutely nothing?
    – vancoder
    May 10, 2013 at 18:13
  • @vancoder , yes absolutely nothing.. I don't know why.. here's the image
    – markyeoj
    May 13, 2013 at 10:51

1 Answer 1


The problem can only be one of the following:

  1. Your taxonomy "recipecategory" does not exist.

  2. Your taxonomy has no terms.

  3. None of your recipecategory terms have any posts. In this case, make the following change:

$tax_terms = get_terms($taxonomy, array('hide_empty' => false));

This should work as it will override the default setting, which is to ignore empty terms.

 foreach($tax_terms as $term_single) {      
  • thanks @vancoder, I thought that its possible to display the categories under my custom taxonomy without creating a posts using the categories. Now I know, thank you so much its a relief. :)
    – markyeoj
    May 14, 2013 at 10:25

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.