cliff
6/16/2016 - 3:10 AM

Excludes specified categories from List and Month views. Add you own categories in line 9.

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 );