I am using the display taxonomy's parent solution here: https://toolset.com/forums/topic/display-taxonomys-parent-in-taxonomy-view/
But instead of just the name I would like it to Link to term archive page.
Can the code be modified to do this?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
You can use the WordPress function get_term_link() to get the term link.
=> https://developer.wordpress.org/reference/functions/get_term_link/
Can you please try to use the following modified code. You can adjust it as required.
add_shortcode('show_tax_term_parent', 'show_tax_term_parent_func');
function show_tax_term_parent_func($atts) {
$taxonomy = $atts['taxonomy'];
$term_id = $atts['term_id'];
$current_term = get_term_by('ID', $term_id, $taxonomy, 'ARRAY_A');
if ( ($current_term) && ($current_term['parent'] != 0) ) {
$parent_term = get_term_by('ID', $current_term['parent'], $taxonomy, 'ARRAY_A');
return '<li><a href="'.get_term_link($parent_term['term_id']).'">'.$parent_term['name'].'</a></li>';
}
}