Skip to content

Instantly share code, notes, and snippets.

@stoffl6781
Created July 29, 2025 10:06
Show Gist options
  • Save stoffl6781/f7bc28b39b72505e2a3e4c5af930d3fc to your computer and use it in GitHub Desktop.
Save stoffl6781/f7bc28b39b72505e2a3e4c5af930d3fc to your computer and use it in GitHub Desktop.
/*
* Try to change IN from a specivic Filter to NOT IN over Query_vars Bricks filter.
*
*/
add_filter( 'bricks/query_filters/filter_query_vars', function( $query_vars, $filter, $query_id, $index ){
$filter_id = $filter['filter_id'] ?? '';
$allowed_filters = array( 'opuozx', 'nbhbmt'); //Bricks Widget Filter ID'S (Array)
if( !in_array( $filter_id, $allowed_filters, true ) ) {
return $query_vars;
}
// Add 'NOT_IN' to the tax_query
if ( isset( $query_vars['tax_query'] ) && is_array( $query_vars['tax_query'] ) ) {
$query_vars['tax_query'][0]['operator'] = 'NOT IN';
$new_tax_query = $query_vars['tax_query'];
if ( isset( \Bricks\Query_Filters::$active_filters[ $query_id ][ $index ] ) ) {
\Bricks\Query_Filters::$active_filters[ $query_id ][ $index ]['query_vars'] = $new_tax_query ;
}
}
return $query_vars;
}, 50, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment