Forked from elimn/tribe_exclude_events_category.php
Last active
November 27, 2022 03:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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