Last active
August 29, 2015 14:09
-
-
Save elimn/6a57feaec4bd09db9923 to your computer and use it in GitHub Desktop.
MT | TEC | Selectively hide events from specific user roles
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 | |
// 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