Display custom taxonomy in shortcode
-
Hello,
I would like to create a shortcode displaying, in a post, all the custom taxonomies attached.
Initialy I have this code for the CPT “secteur”, and it works in a template :
$termsSecteur = get_the_terms( $post->ID , 'secteur' ); if ( $termsSecteur != null ){ foreach( $termsSecteur as $termsSecteur ) { $termsSecteur_link = get_term_link( $termsSecteur, 'secteur' ); echo '<a class="tag-secteur" href="' . $termsSecteur_link . '">' . $termsSecteur->name . '</a>'; unset($termsSecteur); } } ?>
So in my function file I tried this but nothing appears :
function tags_function(){ $termsSecteur = get_the_terms( $post->ID , 'secteur' ); if ( $termsSecteur != null ){ foreach( $termsSecteur as $termsSecteur ) { $termsSecteur_link = get_term_link( $termsSecteur, 'secteur' ); $return .= '<a class="tag-secteur" href="' . $termsSecteur_link . '">' . $termsSecteur->name . '</a>'; unset($termsSecteur); } } } add_shortcode( 'list_tags', 'tags_function' );
Do you know what is wrong here ?
I thank you in advance for your help ! ??
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Display custom taxonomy in shortcode’ is closed to new replies.