I'm using pre_get_posts
to filter by using $wp_query->set( 'tax_query', $tax_query );
I'm probably better-off doing this with a new WP_Query
, but if someone knows something I don't I'd love to hear it
For instance:
/cpt/?taxo=this
shows all cpt's which have a taxo-term == this.
$taxo_terms = [];
if( !empty( $_GET['taxo'] ) ){
$types = explode(',', $_GET['taxo']);
foreach ($types as $key => $val) {
$taxo_terms[$key] = sanitize_key($val);
}
}
else{
$taxo_terms[]='this'; // here's where things get ugly.
}
$tax_query = [];
if( !empty($taxo_terms) ){
$tax_query[] = [
'taxonomy' => 'taxo',
'field' => 'slug',
'terms' => $taxo_terms,
'operator' => 'AND',
];
$wp_query->set( 'tax_query', $tax_query );
}
I want to add /cpt/?taxo=all
to show all posts, regardless of what taxo->terms
they have.
Hoping to find a way to unset
the current tax_query
from the loop, using pre_get_posts
.
Is there a way to $wp_query->UNSET
?
I've tried $wp_query->set( 'tax_query', null );
$wp_query
object inside that filter, taxonomy queries are referenced in multiple places in there. I think you have to manually unset the tax query object that gets created before the filter runs, which is separate from the tax query var thatset
modifies.