Skip Navigation

[Resolved] display taxonomy's parent in taxonomy view – Link to term archive page

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by bobA-2 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2280925

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?

#2281545

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>';
    }
}
#2281951

Thanks that works.