Advertisement
amanda_giles

Filtering Event Categories with 'tribe_events_pre_get_posts'

Jun 29th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. function pnh_filter_tribe_all_occurences ( $query ) {
  2.  
  3.     //If we're in the admin, make no query alterations
  4.     if ( is_admin() )
  5.         return $query;
  6.  
  7.     // Get the event category slug
  8.     $eventcat = (isset( $query->query_vars[Tribe__Events__Main::TAXONOMY] ) && $query->query_vars[Tribe__Events__Main::TAXONOMY] != '' ? $query->query_vars[Tribe__Events__Main::TAXONOMY] : '');
  9.    
  10.     //Check that the event category being called isn't one of the 3 we're excluding
  11.     //(if it is, then don't do the exclusion)
  12.     if ( $eventcat != 'music-club-listings' && $eventcat != 'art-exhibits-events' && $eventcat != 'theater' ) {
  13.  
  14.             //Add a tax query to exclude the Art, Club Listings, and Theater categories by all views (except those specific categories)
  15.             $taxquery = array(
  16.                 array(
  17.                   'taxonomy' => Tribe__Events__Main::TAXONOMY,
  18.                   'field' => 'id',
  19.                   'terms' => array(21,22,17),   //Art = 21, Club Listings = 22, Theater = 17
  20.                   'operator' => 'NOT IN'
  21.                 )
  22.             );              
  23.  
  24.             $query->query_vars['tax_query'][] = $taxquery;        
  25.     }
  26.    
  27.     return $query;
  28. }
  29. add_action('tribe_events_pre_get_posts', 'pnh_filter_tribe_all_occurences',1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement