-
-
Save FrancoStino/19acb4b3b36d078bdbe252a47ef4f9f9 to your computer and use it in GitHub Desktop.
Remove events from a specified event category in "The Events Calendar" by Modern Tribe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The Events Calendar Remove Events from Month and List Views | |
* | |
* @param [object] $query Query of the events page. | |
* @return [object] Modified Query | |
*/ | |
function tribe_exclude_events_category_month_list( $query ) { | |
if ( isset( $query->query_vars['eventDisplay'] ) && ! is_singular( 'tribe_events' ) ) { | |
if ( 'list' === $query->query_vars['eventDisplay'] && ! is_tax( Tribe__Events__Main::TAXONOMY ) || 'month' === $query->query_vars['eventDisplay'] && Tribe__Events__Main::POSTTYPE === $query->query_vars['post_type'] && ! is_tax( Tribe__Events__Main::TAXONOMY ) && empty( $query->query_vars['suppress_filters'] ) ) { | |
$query->set( | |
'tax_query', | |
array( | |
array( | |
'taxonomy' => Tribe__Events__Main::TAXONOMY, | |
'field' => 'slug', | |
'terms' => array( 'filmtournee-unterwegs' ), | |
'operator' => 'NOT IN', | |
), | |
) | |
); | |
} | |
} | |
return $query; | |
} | |
/* | |
I've found several versions on the internet but there aren't working for me, so I digged a little deeper | |
and found the culprit: the priority needs to be above 50 to work as there are using priority 50 themself: | |
https://github.com/moderntribe/the-events-calendar/blob/c0128a69b600d6c279952e0ac7b6aea22d2028bb/src/Tribe/Query.php#L42 | |
*/ | |
add_action( 'pre_get_posts', 'tribe_exclude_events_category_month_list', 51, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment