Skip to content

Instantly share code, notes, and snippets.

@chikaibeneme
Last active November 19, 2020 03:28
Show Gist options
  • Select an option

  • Save chikaibeneme/2030de8ba17f7472c1f2848c2499eb3a to your computer and use it in GitHub Desktop.

Select an option

Save chikaibeneme/2030de8ba17f7472c1f2848c2499eb3a to your computer and use it in GitHub Desktop.
function tribe_exclude_events_category( $wp_query ) {
// only filter the query if the user cannot edit pages (< editor)
if (!current_user_can('edit_pages')) {
$exclude_cats = array('exclude-me');
// Join with current tax query if set
if (is_array($wp_query->get( 'tax_query')))
{$tax_query =$wp_query->get( 'tax_query');}
else
{$tax_query = array();}
// Setup an exclude from the tribe_events_cat taxonomy
$tax_query[] = array(
'taxonomy' => Tribe__Events__Main::TAXONOMY, // sidebar ist: "tribe_events_cat"
'field' => 'slug',
'terms' => $exclude_cats,
'operator' => 'NOT IN'
);
if (!is_single() && !is_tax()) { $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