Get the the top-level parent of a custom taxonomy term

Posted by Prem Tiwari | Updated on

The first function below, get_term_top_most_parent, accepts a term and taxonomy and returns the the term’s top-level parent (or the term itself, if it’s parentless); the second function (get_top_parents) works in the loop, and, given a taxonomy, returns an HTML list of the top-level parents of a post’s terms.

Once you have the function above, you can loop over the results returned by wp_get_object_terms and display each term’s top parent:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers