I am trying to display the terms (from a custom taxonomy) of a single post, but I can’t display more than one term. When I try to display all the terms using a foreach
loop, it doesn’t display anything.
Here is one of my attempts :
<?php $ terms = get_the_terms($ post->ID, 'auteur'); if ($ terms && !is_wp_error($ terms)) { foreach($ terms as $ term) { echo $ term->name ; } } ?>
It doesn’t display anything. But the same code without foreach
loop displays (as expected) one term :
<?php $ terms = get_the_terms($ post->ID, 'auteur'); echo $ term->name ; ?>
I imagine that I’m missing an evident mistake (I’m a beginner), but I can’t understand what is wrong with the foreach
loop…
Thank you !