Get taxonomy that is attached to post with all its parents

You want get_ancestors(). This is pretty crude but… $locations = get_the_terms( $post->ID, ‘category’ ); // var_dump($locations); $pat=”<a href=””.site_url().’/location/%s”>%s</a>’; foreach ( $locations as $location ) { printf($pat,$location->slug,$location->name); $anc = get_ancestors($location->term_id,’category’); if (!empty($anc)) { foreach ($anc as $term) { $t = get_term_by( ‘term_id’, $term, ‘category’); printf($pat,$t->slug,$t->name); } } break; }

Complex Taxonomy scheme

Set your system up like this: locations – CPT administrative – hierarchical taxonomy natural – hierarchical taxonomy type – non-hierarchical taxonomy In the administrative taxonomy, you would create your tree: countries on the first level, regions second, departments and so on. Then, you would assign your locations to the smallest administrative denominations among your taxonomies … Read more