Get Current Post Term Parent by Child ID

$terms = get_the_terms( $post->ID, 'taxonomy' );
foreach($terms as $term) { }
	
$child_term = get_term( $term->term_id, 'taxonomy' );
$parent_term = get_term( $child_term->parent, 'taxonomy' );

echo $term->name;
echo $parent_term->name;

Source.

2 thoughts on “Get Current Post Term Parent by Child ID

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.

%d bloggers like this: