Guest User

Untitled

a guest
Jan 13th, 2014
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. add_filter('pre_get_posts', 'event_cat_permissions');
  2.  
  3. function event_cat_permissions ($wp_query) {
  4.  
  5.     // Include all posts on admin views
  6.     if ( is_admin() ) return $wp_query;
  7.  
  8.  
  9.     $exclude_cats = array();
  10.  
  11.     // Exclude cats if not admin... copy/modify this logic for each custom role
  12.     if (!current_user_can('administrator')) {
  13.         $exclude_cats[] = 'exclude-slug';
  14.     }
  15.  
  16.  
  17.     // Join with current tax query if set
  18.     if (is_array($wp_query->tax_query))
  19.         $tax_query = $wp_query->tax_query;
  20.     else
  21.         $tax_query = array();
  22.  
  23.  
  24.     // Setup an exclude from the tribe_events_cat taxonomy
  25.     $tax_query[] = array(
  26.         'taxonomy'  => 'tribe_events_cat',
  27.         'field'     => 'slug',
  28.         'terms'     => $exclude_cats,
  29.         'operator'  => 'NOT IN'
  30.     );
  31.  
  32.     $wp_query->set('tax_query', $tax_query);
  33.  
  34.     return $wp_query;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment