Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save theeventscalendar/c9580839c3a76778d583 to your computer and use it in GitHub Desktop.
Save theeventscalendar/c9580839c3a76778d583 to your computer and use it in GitHub Desktop.
Excludes specified categories from List and Month views. Add you own categories in line 9.
<?php
/*
* Removes categories "meetup" and "shindig" from list and month views
*/
function tribe_exclude_events_category( $wp_query ) {
// Slugs for the categories you wish to hide
$exclude_cats = array('meetup', 'shindig');
// Include all posts on admin views
if ( is_admin() ) return $wp_query;
// Uncomment to allow admins to view all events
// if ( current_user_can('administrator') ) return $wp_query;
// Join with current tax query if set
if (is_array($wp_query->tax_query))
$tax_query = $wp_query->tax_query;
else
$tax_query = array();
// Setup an exclude from the tribe_events_cat taxonomy
$tax_query[] = array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => $exclude_cats,
'operator' => 'NOT IN'
);
if (
tribe_is_event_query()
// && !is_single() // Uncomment to allow directly viewing an individual event page
// && !is_tax() // Uncomment to allow directly viewing the category page
) {
$wp_query->set('tax_query', $tax_query);
}
return $wp_query;
}
add_action( 'pre_get_posts', 'tribe_exclude_events_category', 100, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment