Advertisement
brook-tribe

Filter Past Events from View All Occurences

Jun 7th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100);
  2.  
  3. function filter_tribe_all_occurences ($wp_query) {
  4.  
  5.     $te = TribeEvents::instance();
  6.  
  7.     if($te->displaying == 'all') {
  8.  
  9.         $new_meta = array();
  10.         $today = new DateTime();
  11.  
  12.         // Join with existing meta_query
  13.         if(is_array($wp_query->meta_query))
  14.             $new_meta = $wp_query->meta_query;
  15.  
  16.         // Add new meta_query, select events ending from now forward
  17.         $new_meta[] = array(
  18.             'key' => '_EventEndDate',
  19.             'type' => 'DATETIME',
  20.             'compare' => '>=',
  21.             'value' => $today->format('Y-m-d H:i:s')
  22.         );
  23.  
  24.         $wp_query->set( 'meta_query', $new_meta );
  25.     }
  26.  
  27.     return $wp_query;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement