Created
November 28, 2013 23:50
-
-
Save 5iDS/7699644 to your computer and use it in GitHub Desktop.
WP determine the topmost parent of a term
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function get_term_top_most_parent($term_id, $taxonomy){ | |
| // start from the current term | |
| $parent = get_term_by( 'id', $term_id, $taxonomy); | |
| // climb up the hierarchy until we reach a term with parent = '0' | |
| while ($parent->parent != '0'){ | |
| $term_id = $parent->parent; | |
| $parent = get_term_by( 'id', $term_id, $taxonomy); | |
| } | |
| return $parent; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment