0

I have a term referenced by $id. The term is inside a tree of levels.

rootlevel parent (parent=0)
    first level parent
       second level parent
           ...
           ...
           last level parent
                many terms, my term $id

How can I get all the parents: root level, first level, second level ..., last level parent of my term?

2
  • Have you attempted anything to achieve this?
    – Howdy_McGee
    Oct 17, 2014 at 15:05
  • I am trying a while loop with condition parent!=0, but I guess there is a wp function to do this.
    – emanuele
    Oct 17, 2014 at 15:13

1 Answer 1

7

You can get all of the parents of an object via get_ancestors -

$term_id = 42;
$your_taxonomy = 'sometax';
$parents = get_ancestors( $term_id, $your_taxonomy );

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.