Skip to content

Instantly share code, notes, and snippets.

@quasel
Forked from Zodiac1978/functions.php
Created August 14, 2020 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quasel/79ae560a8ff04a75b285f0af730a6da6 to your computer and use it in GitHub Desktop.
Save quasel/79ae560a8ff04a75b285f0af730a6da6 to your computer and use it in GitHub Desktop.
Remove events from a specified event category in "The Events Calendar" by Modern Tribe
<?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