Created
April 28, 2015 14:17
-
-
Save BeardedGinger/9bddfdd0fbb3368cc45d to your computer and use it in GitHub Desktop.
get the lowest level term assigned to a post from a hierarchical taxonomy
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
| <?php | |
| //Find the lowest term on the totem pole | |
| $parents = array(); | |
| $regions = get_the_terms( get_the_ID(), 'regions' ); | |
| foreach( $regions as $region ) { | |
| $parents[] = $region->parent; | |
| } | |
| foreach( $regions as $region ) { | |
| // if the current term isn't another's parent, it has to be the lowest right? | |
| if( !in_array( $region->term_id, $parents ) ) { | |
| $location = $region->name; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment