You should be using methods of the $query
instance instead of the is_*
template tags. And are the categories you are trying to filter a custom taxonomy? cat
only works on the default category
taxonomy:
function wpse_178500_event_type_filter( $wp_query ) {
if ( ! empty( $_GET['event_term'] ) && $wp_query->is_main_query() && $wp_query->get( 'post_type' ) === 'event' ) {
$tipo_de_curso = $_GET['event_term'];
if ( ! $tax_query = $wp_query->get( 'tax_query' ) )
$tax_query = array();
if ( $tipo_de_curso === 'singleclass' ) {
$tax_query[] = array(
'taxonomy' => 'category', // Make sure this is correct! "category" is the default post category.
'field' => 'term_id',
'terms' => array( 1, 2, 3, 4 ),
);
} elseif ( $tipo_de_curso === 'course' ) {
$tax_query[] = array(
'taxonomy' => 'category', // Make sure this is correct! "category" is the default post category.
'operator' => 'NOT IN',
'field' => 'term_id',
'terms' => array( 1, 2, 3, 4 ),
);
}
$wp_query->set( 'tax_query', $tax_query );
}
}
add_action( 'pre_get_posts','wpse_178500_event_type_filter' );