Event calendars come in all shapes and sizes, and the need might come up to hide some events from the main calendar views that are in specific event categories. The below snippets comes to the rescue.

👋 Note, that this will still make the event page accessible if one knows the URL.

Hide in all views

This snippet will hide the events in all main calendar views. Note that this also affects calendars displayed with the [tribe_events]shortcode. (See below for a solution to exclude that.)

If you don’t know how to use snippets check our detailed article about Using Custom Code Snippets to get detailed instructions.

add_filter( 'tribe_events_views_v2_view_repository_args', 'tec_exclude_events_category', 10, 3 );

function tec_exclude_events_category( $repository_args, $context, $view ) {
	// List of category slugs to be excluded
	$excluded_categories = [
		'my-category-slug',
		'my-other-category-slug',
	];
	$repository_args['category_not_in'] = $excluded_categories;

	return $repository_args;
}

Hide in some views

If don’t want to hide it in all views then you can do that with a small modification, where you check for the current view.

add_filter( 'tribe_events_views_v2_view_repository_args', 'tec_exclude_events_category', 10, 3 );

function tec_exclude_events_category( $repository_args, $context, $view ) {
	// List of views where the category should be hidden
	$hide_in_views = [
		'month',
		'list',
	];

	if ( in_array( $view->get_slug(), $hide_in_views, true ) ) {
		// List of category slugs to be excluded
		$excluded_categories = [
			'my-category-slug',
			'my-other-category-slug',
		];
		$repository_args['category_not_in'] = $excluded_categories;
	}

	return $repository_args;
}

Hide in one view only

While you can use the above snippet to hide the specific events in one view only, there are dedicated hooks for each view separately. So you could also do this:

add_filter( 'tribe_events_views_v2_view_month_repository_args', 'tec_exclude_events_category', 10, 3 );
add_filter( 'tribe_events_views_v2_view_list_repository_args', 'tec_exclude_events_category', 10, 3 );
add_filter( 'tribe_events_views_v2_view_day_repository_args', 'tec_exclude_events_category', 10, 3 );
add_filter( 'tribe_events_views_v2_view_photo_repository_args', 'tec_exclude_events_category', 10, 3 );
add_filter( 'tribe_events_views_v2_view_week_repository_args', 'tec_exclude_events_category', 10, 3 );
add_filter( 'tribe_events_views_v2_view_map_repository_args', 'tec_exclude_events_category', 10, 3 );

function tec_exclude_events_category( $repository_args, $context, $view ) {
	// List of category slugs to be excluded
	$excluded_categories = [
		'my-category-slug',
		'my-other-category-slug',
	];
	$repository_args['category_not_in'] = $excluded_categories;

	return $repository_args;
}

Choose the hooks that you need.

Hide only on shortcode page

The above snippets will run on both the main calendar pages and the ones created with the [tribe_events] shortcode. If you would like to hide only on shortcode pages, then you will need the following:

add_filter( 'tribe_events_views_v2_view_repository_args', 'tec_exclude_events_category', 10, 3 );

function tec_exclude_events_category( $repository_args, $context, $view ) {
	// If not shortcode calendar then bail and show everything
	if ( ! $context->is('shortcode') ) {
		return $repository_args;
	}
	
	// List of category slugs to be excluded
	$excluded_categories = [
		'my-category-slug',
		'my-other-category-slug',
	];
	$repository_args['category_not_in'] = $excluded_categories;

	return $repository_args;
}

Of course that can be turned around. If you only want to hide the events on main calendar pages then you need to remove the exclamation point on line 5, so it would look like this:

	if ( $context->is('shortcode') ) {

Enjoy!