How to get the the top-level parent of a custom taxonomy term?

Posted by Jessica Taylor | Updated on

If you want to get the the top-level parent of a custom taxonomy term? 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[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers