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

Custom Permalinks with CPT and Hierarchical Taxonomies

CPT does’t have much options for building custom permalinks. What you need can’t be done without custom coding and creating new rewrite rules, and handling permalink parsing. I have plugin for working with post types and taxonomies, and it includes options for custom permalinks and more. It is not a free plugin, but in many … Read more

WP Rewrite Rule Issue while using Custom post type & taxonomy

Don’t really know why but here is a working solution : $blogCategoryBaseSlug = ‘articles’; $labels = array( ‘name’ => __( ‘Blog Post’, ‘Post Type General Name’, $this->text_domain ), ‘singular_name’ => __( ‘Blog Post’, ‘Post Type Singular Name’, $this->text_domain ), ‘menu_name’ => __( ‘Blog Posts’, $this->text_domain ), ‘name_admin_bar’ => __( ‘Blog Post’, $this->text_domain ), ‘archives’ => … Read more