Advertisement
Guest User

Untitled

a guest
Sep 6th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Limit events to upcoming only
  5.  */
  6.  
  7. function event_listings( $query ) {
  8.    
  9.     $path = get_current_path();
  10.     if( ( $path['exploded'][1] === 'clubs' ) && ( $path['exploded'][3] === 'events' ) ) {
  11.         $club_specific_event_archive = TRUE;   
  12.     } elseif( ( $path['exploded'][1] === 'koru-lounge' ) && ( $path['exploded'][2] === 'events' ) ) {
  13.         $koru_lounge_event_archive = TRUE; 
  14.     }
  15.    
  16.     if( ( $query->is_main_query() ) && ( !is_admin() ) && ( ( is_post_type_archive( 'event_post' ) ) || ( ( $club_specific_event_archive == TRUE ) || ( $koru_lounge_event_archive == TRUE ) ) ) ) {
  17.        
  18.         $today = date("Y-m-d",strtotime("today"));
  19.        
  20.         if( ( $club_specific_event_archive == TRUE ) || ( $koru_lounge_event_archive == TRUE ) ) {
  21.            
  22.             if( $koru_lounge_event_archive == TRUE ) {
  23.                 $meta_value = $path['exploded'][1];
  24.             } else {
  25.                 $meta_value = $path['exploded'][2];
  26.             }
  27.             $meta_value = ucwords( str_replace( "-", " ", $meta_value ) );
  28.            
  29.             $venue_specific = array(
  30.                 'key' => '_event_venue',
  31.                 'value' => $meta_value,
  32.                 'compare' => 'LIKE'
  33.             );
  34.            
  35.             $query->set( 'is_page', '' );
  36.             $query->set( 'is_singular', '' );
  37.            
  38.         }
  39.        
  40.         $meta_query = array(
  41.             array(
  42.                 'key' => '_event_date',
  43.                 'value' => $today,
  44.                 'compare' => '>=',
  45.             ),
  46.             $venue_specific
  47.         );
  48.         $query->set( 'meta_query', $meta_query );
  49.         $query->set( 'post_status', 'publish' );
  50.         $query->set( 'meta_key', '_event_date' );
  51.         $query->set( 'orderby', 'meta_value' );
  52.         $query->set( 'order', 'ASC' );
  53.         $query->set( 'ignore_sticky_posts', 1 );
  54.        
  55.         // echo "<pre>"; print_r( $query ); echo "</pre>";
  56.        
  57.     }
  58.    
  59. }
  60. add_action( 'pre_get_posts', 'event_listings' );
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement