@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
- When to use WP_query(), query_posts() and pre_get_posts
- Should I use Pre Get Posts or WP_Query
- Using pre_get_posts with WP_Query
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- What is “main query”? [duplicate]
- WP query taxonomy input differs to output?
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- Search custom taxonomy term by name
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- How to uniquely identify queries?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- How to display post from current Taxonomy in archive page?
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- Changing Posts Per Page and offset with pre_get_posts
- Display posts the match taxonomy term linked from wp_list_categoies?
- Slow SQL_CALC_FOUND_ROWS Query
- “pre_get_posts” firing on every query
- Why is my WP_Query not working when tax_query terms are an array?
- RSS feed with specific keyword
- Using is_main_query to select custom post type on certain page
- Multiple orderby parameters in pre_get_posts() action
- 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
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- Query with pre_get_posts to get pagination
- Querying Multiple Custom Taxonomy Terms
- Recommended way to drop a pending query (in pre_get_posts)?
- Single page theme that uses pages for the content
- WordPress custom search form with pre_get_posts not work
- If orderby parameter using pre_get_posts is the same for multiple posts what fallback does the query use?
- Can not switch the queried post in pre_get_posts hook
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- Filter and list posts of a custom taxonomy
- order by multiple meta keys in 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?
- WP_Tax_Query with post_tag not working
- Filter WordPress posts by between parameter
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Using pre_get_posts on a specific core/query block
- 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
- Filtering posts by custom field value not working
- How to display future posts – modified query still yields 404
- Display link to taxonomy archive only if it has posts with certain custom field values
- pre_get_posts filter meta_query without conflicting existing meta_query
- Including only current user’s posts in search
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?
- How to change posts order on Category and Tag archives?
- Order taxonomy terms in alphabetical order
- Is it possible to dynamically get queried term AND taxonomy?
- WP Query for variable taxonomies
- How do I search inside specific taxonomies in WordPress
- Pass array of taxonomy terms to wp_query
- My Main Query Modification is Messing up my dynamic main – why?
- Offset Page Loops and Pagination
- pre_get_posts Remove tax_query Completely
- pre_get_posts order by not working
- Adding a parameter to the default query
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- Taxonomy search/filter with multiple taxonomies and multiple taxonomy terms
- Single meta_query query using OR instead of AND in request’s WHERE statement
- Order by slug in get_terms with multiple taxonomies
- Output an array of terms for a ‘tax_query’ => array()
- How to choose between hooking into per_get_posts or into parse_query
- Function get_queried_object() return NULL in custom taxonomy
- Getting Taxonomy inside WP_Query Loop
- Store sticky post’s ids in a transient
- How to change main query based on post meta
- Complex WP_Query (two post types and multiple operators)
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- new WP_Query to get max price meta value not working
- Display posts from only one post form in custom query and exclude in main query
- Show Sticky Post at the top but do not show again in the loop?
- WP_Query, pre_get_posts and offset
- Complex WP SQL Query
- Using meta_query with multiple keys and compare values
- Can I set my WP_Query to be a Main Query?
- is_tax() function not working as expected
- Advanced Taxonomy Queries WordPress
- Show scheduled posts in main loop but not in WP_Query?
- Display Featured Post by Categories and Avoid duplicated posts
- Get authors by term id or slug
- WP_Query tax query part of slug
- Taxonomy Query Relation field not behaving correctly?
- WP Query Args – Title or Taxonomy Value
- How to Union two different conditions in one WP_Query
- hide custom post types with specific meta key ON admin backend
- WP_Query ignoring tax_query when is_singular
- 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’