I’m trying to remove an Event Category (id:462) from all event queries (except that category’s landing page) and it works fine on page load, but doesn’t seem to be honored when query results are loaded via ajax.
The following code works on events page load, and if I were to load an event search query directly on a page (i.e., reloading the results), but if I do anything that would reload the query via AJAX it is not honored (such as paginating, or entering a new search). When that happens, events of the category 462 still show up.
I’m thinking that somewhere the date query is superseding this query modifications, but no matter what I set as a the priority of this modification, the AJAX calls are still not catching it. Any ideas?
// Tribe Events modifications to the query
function events_mod( $query ) {
if( !is_admin() && $query->is_main_query() && !is_tax('tribe_events_cat') && !tribe_is_event() && ( tribe_is_past() || tribe_is_upcoming() ) ) {
$taxquery = array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'id',
'terms' => array( 462 ),
'operator' => 'NOT IN'
)
);
$query->set( 'tax_query', $taxquery );
}
return $query;
}
add_action( 'tribe_events_pre_get_posts', 'events_mod', 1);