Wordpress get current post term parent by child ID

Mantas Kudeikis picture Mantas Kudeikis · Jan 29, 2013 · Viewed 22.9k times · Source

In page I have ID of term child, I need find out this child parent by child ID, it's passible, maybe someone can help with this ?

Answer

Joseph Silber picture Joseph Silber · Jan 29, 2013

That's what the get_term function is for:

$term_id = 21; // Lucky number :)

$child_term = get_term( $term_id, 'category' );
$parent_term = get_term( $child_term->parent, 'category' );

Replace 'category' with whatever taxonomy you're using.