Skip to content

Instantly share code, notes, and snippets.

@elimn
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elimn/6a57feaec4bd09db9923 to your computer and use it in GitHub Desktop.
Save elimn/6a57feaec4bd09db9923 to your computer and use it in GitHub Desktop.
MT | TEC | Selectively hide events from specific user roles
<?php
// Selectively hide events from specific user roles
function tribe_event_category_permissions ($wp_query) {
// Include all posts on admin views
if ( is_admin() ) return $wp_query;
$exclude_cats = array();
// Exclude cats if not admin... copy/modify this logic for each custom role
if (!current_user_can('administrator')) {
$exclude_cats[] = 'exclude-slug';
}
// 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'
);
$wp_query->set('tax_query', $tax_query);
return $wp_query;
}
add_filter('pre_get_posts', 'tribe_event_category_permissions');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment