I have new taxonomy "car-brand" and I want to show name of parent taxonomy in child taxonomy page.

My hierarchical taxonomy:


For example, when user is in F20 taxonomy page I want show this with url:

brand: BMW {level 1 taxonomy}
series: series1 {level 2 taxonomy}

1 Answer 1


You can use get_ancestors() to get an array of IDs of the ancestors of a term in any taxonomies, and in your case, you would use the last 2 items like the example below, where I used:

// Get the current term ID.
$cat_id = get_queried_object_id();

// Get the term's ancestors.
$parents = get_ancestors( $cat_id, 'car-brand' );

// Get the level 1 ancestor term, and display it.
$brand_cat_id = array_pop( $parents );
    'brand: <a href="%s">%s</a><br />',
    esc_url( get_term_link( $brand_cat_id ) ),
    esc_html( get_term_field( 'name', $brand_cat_id ) )

// Get the level 2 ancestor term, and display it.
$series_cat_id = array_pop( $parents );
    'series: <a href="%s">%s</a>',
    esc_url( get_term_link( $series_cat_id ) ),
    esc_html( get_term_field( 'name', $series_cat_id ) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.