Display posts from specific slug of the custom taxonomy in WordPress

I would recommend becoming intimately familiar with the WP_Query parameters: https://developer.wordpress.org/reference/classes/wp_query/ In your particular case; dealing with taxonomies: https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters Here is the proper code to pull from a taxonomy: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘units’, ‘field’ => ‘slug’, ‘terms’ => $term->slug ), ), ); $query = new WP_Query( … Read more

How to looping taxonomy terms?

Rather than relying on a literal menu, you could use wp_list_pages possibly to better effect and sort out by certain criteria if you wish, then foreach page, display terms. Here is a little function I wrote to spit out terms for a taxonomy passed to it: // give taxonomy, will return link list to custom … Read more

Loop posts without any taxonomy

One solution would be to give a value of “none” to your posts without any post group, similarly as you have “uncategorized” posts in WP Categories. Alternatively… I haven’t checked it, but why don’t you try to make another WP_QUERY like this: new WP_Query( array( ‘post_type’ => ‘page’, ‘page_group’ => ” ) )

Querying posts globally based on custom taxonomy with its own taxonomymeta table

For those running into issues in the future, this is what I did: I made my pre_get_posts function that queries the taxonomy as normal for testing if an taxonomy ID is not in a list: $q->set( ‘tax_query’, array(array( ‘taxonomy’ => ‘tax’, ‘field’ => ‘id’, ‘terms’ => tax_get_inactive(), ‘operator’ => ‘NOT IN’ ))); Then, I implemented … Read more

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