Given a taxonomy term (perhaps in a taxonomy*.php template) how to construct a breadcrumb going up the full ancestry of the term?

Is there any shorter way other than a "brute-force" loop to query current term's parent -> query term's parent -> query term's parent etc.?

1 Answer 1


You can use get_ancestors for this:

get_ancestors( $term_id, 'taxonomy' );

Of course this will only work on hierarchical elements. Additionally, this will only work reasonably well if only one term per level is assigned, take a look at my comment here and my answer here to get a little bit deeper insight into that.

  • OK get_ancestors() helps a bit, but only gets IDs. Is there nothing shorter / more to-the-point for this? I was hoping since wp_list_categories() exists, WP should also have something like get_term_breadcrumb() or wtvr... I guess not then?
    – xyphenor
    Nov 28, 2013 at 2:20
  • There is get_the_term_list, but it doesn't get ancestors. What wordpress should additionally have is up for debate I guess. Have you read the answer I linked? There I pretty much explain how to do what you want. @xyphenor Nov 28, 2013 at 15:04

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.