I am trying to change an argument in the tax query in the main WP_QUERY object for creating the archive view for my the archive of my hierarchical taxonomy. My goal is to change one of the arguments in the tax query while leaving the rest intact.
I tried to get the current query, modify the tax_query array and then pass it to set.
add_action( 'pre_get_posts', 'slug_cpt_category_archives' );
function slug_cpt_category_archives( $query ) {
if ( is_tax( 'TAXONOMY NAME') ) {
$tax_query = $query->tax_query->queries;
$tax_query['include_children'] = 0;
$query->set( 'tax_query', $tax_query );
}
}
Not only did it not produce the desired effect, of not including child terms, when I add this action:
add_action( 'wp_head', 'preh' );
function preh( ) {
global $wp_query;
print_r( $wp_query->tax_query );
}
I see that there are now two tax_queries and both have [include_children] => 1
pre_get_posts
is an action, not a filter. You could try usingadd_action()
, and remove thereturn $query
. I don't think it will make a difference, but worth a try?