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
<?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
The problem can only be one of the following:
Your taxonomy “recipecategory” does not exist.
Your taxonomy has no terms.
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.