Need to add a link on all single pages for custom post type taxonomy terms which links back to the taxonomy term archive the single page belongs to.
Using this code but it adds links for all tax terms. I only need the one the single page is assigned to.
$terms = get_terms( array(
'taxonomy' => 'portfolio',
) );
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
foreach ( $terms as $term ) {
echo '<a href="' . get_term_link( $term->slug, 'portfolio' ) . '">' . $term->name . '</a>';
}
}
I added this code in the single-portfolio.php file
Need to add a link on all single pages for custom post type taxonomy terms which links back to the taxonomy term archive the single page belongs to.
Using this code but it adds links for all tax terms. I only need the one the single page is assigned to.
$terms = get_terms( array(
'taxonomy' => 'portfolio',
) );
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
foreach ( $terms as $term ) {
echo '<a href="' . get_term_link( $term->slug, 'portfolio' ) . '">' . $term->name . '</a>';
}
}
I added this code in the single-portfolio.php file
Share Improve this question edited Sep 23, 2019 at 18:59 Brad Dalton asked Sep 23, 2019 at 18:43 Brad DaltonBrad Dalton 6,9852 gold badges36 silver badges47 bronze badges1 Answer
Reset to default 1Seems like a good use for get_the_term_list()
https://codex.wordpress/Function_Reference/get_the_term_list