@birgire answer is fine (+1 from me), however $query->tax_query->queries
can contain more than one taxonomy, and $query->tax_query->queries[0]
can be the query for another taxonomy.
So, if you want to set 'include_children'
to false (note that it is a boolean argument) on the taxonomy ‘TAXONOMY NAME’, then you should be sure that you act on right taxonomy:
add_action( 'pre_get_posts', 'slug_cpt_category_archives' );
function slug_cpt_category_archives( $query ) {
if ( is_tax( 'TAXONOMY NAME' ) ) {
foreach ( $query->tax_query->queries as $i => $tax_query ) {
if ( $tax_query['taxonomy'] === 'TAXONOMY NAME' ) {
$query->tax_query->queries[$i]['include_children'] = false;
// if you want to set 'include_children' to false for all
// taxonomies than remove following return
return;
}
}
}
}
Related Posts:
- How to Modify Taxonomy Archive Page with Search Parameter?
- Formulate a url to show posts with both taxonomy terms
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Exclude post with taxonomy and from the terms (taxonomy & tag) posts count
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- Reduce or prevent calling of update_meta_cache
- How-to exclude terms from the main query the most performant way?
- Display posts the match taxonomy term linked from wp_list_categoies?
- Slow SQL_CALC_FOUND_ROWS Query
- Why is my WP_Query not working when tax_query terms are an array?
- SQL Statement generated by WP_Query not producing expected results
- Move posts to top of WP_Query if in certain Taxonomy?
- Sorting Posts by custom field
- Querying Multiple Custom Taxonomy Terms
- Recommended way to drop a pending query (in pre_get_posts)?
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- WP Query – Get WooCommerce Products with variation that is in stock
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- How to add terms to my tax_query based off of the current post
- Searching through different categories on different pages code is not working
- How to display future posts – modified query still yields 404
- Including only current user’s posts in search
- Order taxonomy terms in alphabetical order
- WP Query for variable taxonomies
- How do I search inside specific taxonomies in WordPress
- pre_get_posts Remove tax_query Completely
- Single meta_query query using OR instead of AND in request’s WHERE statement
- How to choose between hooking into per_get_posts or into parse_query
- Getting Taxonomy inside WP_Query Loop
- Store sticky post’s ids in a transient
- new WP_Query to get max price meta value not working
- Show Sticky Post at the top but do not show again in the loop?
- WP_Query, pre_get_posts and offset
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- Show scheduled posts in main loop but not in WP_Query?
- Display Featured Post by Categories and Avoid duplicated posts
- WP Query Args – Title or Taxonomy Value
- hide custom post types with specific meta key ON admin backend
- Slow queries on a huge database
- How do I exclude the lowest level terms in a taxonomy?
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- wp_query args adding muitiple tax_querys
- Automatically Query Parent Taxonomy
- Shouldn’t I be able to modify the main query by this filter?
- pre_get_posts – Trying to get property of non-object warning
- Get posts from multiple tax terms
- How to Order a list of taxonomies? orderby?
- How to add custom meta to ‘pre_get_terms’?
- queried_object using pre_get_posts gets notices and warning
- date_query in pre_get_posts out of memory
- WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
- Get posts in taxonomy randomly
- Loop posts based on permalink term
- Multiple meta_key ordering with pre_get_posts
- Sorting search results with custom dropdown
- pre_get_posts – editing query, tax_query
- Child pages not affected by orderby
- How to get posts by category and by choosing a taxonomy term?
- Don’t repeat posts from children in parent taxonomy query
- How to apply pre_get_posts to a custom query?
- Show multiple tax_query from 2 or more post_type in a single code
- WP_Query, Paginate by Custom Field
- Strange behaviour of hierarchical taxonomy archive
- Block internal search queries with pre_get_posts and regex rules
- How can I order a post query’s results based on the number of matching taxonomy terms?
- WP Query should show No Posts when tax_query $args taxonomies don’t have associated posts
- is_user_logged_in not working from WP-API (wp-json)
- Only show tag with the same id as the post
- Search Exact on WordPress – Relevannsi Solution Not Working
- Excluding posts from search results page with meta query not working
- How to use the Term Object from a custom select field in a query
- pre_user_query vs pre_get_posts
- Can I alter the main loop to ‘orderby’ a custom callback?
- wp_query with meta_query and tax_query
- How can I re-query post_type and rewrite the url?
- WordPress – Form does not filter the results of taxonomies
- Show one post of each custom taxonomy
- Pre_get_posts only show posts by administrator roles
- How to break up output of posts for different terms on same page?
- Modify a query with no results in pre_get_posts
- How order by works?
- Custom Order Current Query: By Meta Key and Category
- Taxonomy archive, categorised by other taxonomy, not hiding empty taxonomies
- taxquery taxonomy get terms
- pages shortcode filtering by category
- How to show terms from another taxonomy
- Modify query to exclude certain ids and certain parents and its corresponding children
- Search format not matching taxonomy query
- wp_query – Modify $query to include duplicate content
- pre_get_posts or $where, which one to use?
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- Avoiding page loop
- Custom post types loop on a page template
- Multiple Orderby is not working right
- Pre_get_post on CPT archive page