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

How do loop categories post from according in WordPress? is it impossible to solve this problem?

Thanks all for help here the link about solved it bcworkz (@bcworkz) 37 minutes ago There are two issues I see. $cat_array is an array of IDs, not objects, so the ‘cat’ query arg should just be ‘cat’ => $cat, The other is when you use setup_postdata( $post ), you must explicitly declare global $post;