Skip to content

Instantly share code, notes, and snippets.

@jentheo
Last active October 10, 2017 21:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jentheo/676f4c627246db43ad36a3d484ebb91e to your computer and use it in GitHub Desktop.
Save jentheo/676f4c627246db43ad36a3d484ebb91e to your computer and use it in GitHub Desktop.
Exclude certain categories from all views (except category pages)
<?php
/*
* The Events Calendar Remove Events from All Views (Except Category Pages)
* add to theme's functions.php file
* @version 4.5.5
* replace these example slugs with your event category slugs: array( 'family-fun', 'bbq' )
*/
add_action( 'pre_get_posts', 'tribe_exclude_events_categories_all_views' );
function tribe_exclude_events_categories_all_views( $query ) {
if ( $query->query_vars['post_type'] == Tribe__Events__Main::POSTTYPE && isset( $query->query_vars['eventDisplay'] ) && ! is_singular( 'tribe_events' ) && ! is_tax( Tribe__Events__Main::TAXONOMY ) ) {
{
$query->set( 'tax_query', array(
array(
'taxonomy' => Tribe__Events__Main::TAXONOMY,
'field' => 'slug',
'terms' => array( 'family-fun', 'bbq' ),
'operator' => 'NOT IN'
)
) );
}
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment