Group Post by Custom Taxonomy 2 under Custom Taxonomy 1

Presumably that would be in your taxonomy-business-location.php template file then. Here’s what the main content area could look like in such a template, basically: <div id=”main-content”> <?php $business_location = get_queried_object(); echo “<h1 class=”business-location-title”>Businesses in ” . $business_location->name . “:</h1><hr>”; // Location A, according to your example $business_categories = get_terms( [ ‘taxonomy’ => ‘business-category’, ‘hide_empty’ => … Read more

How do I display the grand child items of a taxonomy term?

I managed to answer this question myself by adding get_queried_object()->term_id; instead of the taxonomy terms ID. It now outputs all the grandchild taxonomy terms for the current taxonomy term. Here is my updated working code: $term_id = get_queried_object()->term_id; $taxonomy_name=”product_range”; $term_children = get_term_children( $term_id, $taxonomy_name ); echo ‘<ul>’; foreach ( $term_children as $child ) { $term … Read more

How do I check if the user is on a taxonomy term parent, child or grandchild page?

Try get_ancestors(): $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); $ancestors = get_ancestors( $term->term_id, ‘product_range’, ‘taxonomy’ ); $hierarchy_levels = count( $ancestors ); switch ( $hierarchy_levels ) { case 0: // THIS IS THE PARENT CATEGORY // DO YOUR STUFF break; case 1: // THIS IS THE PARENT CATEGORY // DO YOUR STUFF … Read more

How to conditionally redirect to the post from a taxonomy page?

I think you can simply use WP_Term‘s $count property which should hold the number of posts attached to this current term.Then, if only one post is attached to this term, query this post object and do your stuff with it… $term = get_queried_object(); if ( $term->count === 1 ) { $args = array( ‘tax_query’ => … Read more

How do I exclude the lowest level terms in a taxonomy?

If you have only 4 level, and each third level term has children, the we can determine the fourth level term if have children: $term_id = get_queried_object()->term_id; $taxonomy_name=”product_range”; $custom_terms = get_term_children( $term_id, $taxonomy_name ); foreach ( $custom_terms as $custom_term ) { $term = get_term_by( ‘id’, $custom_term, $taxonomy_name ); $terms_chilren = get_term_children( $term_id, $taxonomy_name ); wp_reset_query(); … Read more

Posts list in custom taxonomy

$term isn’t being set anywhere in your code. You’re putting IDs into $terms_ids, but then in your query you’re using $term->term_id. $term doesn’t exist outside of the foreach. You need to be passing $terms_ids directly into terms: $terms = get_the_terms( get_the_ID(), ‘kosmetyki_dystrybutor’); $terms_ids = []; foreach ( $terms as $term ) { $terms_ids[] = $term->term_id; … Read more

Set a CPT slug as a base name for all the taxonomies

I think if you change the rewrite in your register_taxonomy $args ‘rewrite’ => array( ‘slug’ => ‘photographies/couleurs’,’with_front’ => false ), This will probably clash with rewriting the custom post type so you’ll more than likely get a 404 on this url: http://thewebsite/photographies/ but if you don’t need that url then this solution will help you … Read more