I’ll start by saying that I have no background in php.
I need to embed a shortcode to display the name of the specific taxonomy the post is associated with.
I found an answer that seems close to what I’m looking for.
The answer from this page:
Displaying taxonomy term instead of category in title
The code shown there in the solution is:
// Get taxonomy terms specifc to current post
$terms = get_the_terms( $post->ID , 'your-taxonomy-name-here' );
foreach ( $terms as $term ) {
echo ' <a href="' .esc_url( home_url( '/' ) ). $term->slug . '" title="' . $term->name . '" ' . '>' . $term->name .'</a> ';
}
According to this code I tried the following code, without success:
// Get taxonomy terms specifc to current post
$terms = get_the_terms( $post->ID , 'dish_type' );
foreach ( $terms as $term ) {
echo ' <a href="' .esc_url( home_url( '/' ) ). $term->slug . '" title="' . $term->name . '" ' . '>' . $term->name .'</a> ';
}
add_shortcode('dish_type', 'get_the_terms');
Remarks:
- I don’t need a link to the taxonomy.
- I tried to replace ‘your-taxonomy-name-here’ with the Taxonomy Key: dish_type
- Did I correctly add the add_shortcode?
I would appreciate your help