Skip to content

Instantly share code, notes, and snippets.

@elimn
Created June 5, 2015 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elimn/c47fb3e65d437c2479bd to your computer and use it in GitHub Desktop.
Save elimn/c47fb3e65d437c2479bd to your computer and use it in GitHub Desktop.
MT | TEC | Selectively hide event categories from main views
<?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