List the categories under custom taxonomy

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

Read More
<?php

$taxonomy = 'recipecategory';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
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>';
}
?>
</ul>

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

Related posts

1 comment

  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) {      
             $term_single->slug;  
             $term_single->name;        
     } 
    

Comments are closed.