Guest User

ECP loop

a guest
Oct 22nd, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. <?php
  2.         global $post;
  3.        
  4.        
  5.         // GET search variables from URL
  6.         $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  7.         $search = get_query_var('s');
  8.         $tax_slug = sanitize_text_field($_GET['tax_id']);
  9.         $venue = sanitize_text_field($_GET['venue']);
  10.         $start_date = sanitize_text_field($_GET['start_date']);
  11.        
  12.         if($start_date){
  13.             $e_date =  date('Y-m-d H:i:s',strtotime("+30 days", strtotime($start_date)));
  14.             $s_date =  date('Y-m-d H:i:s',strtotime("-1 day", strtotime($start_date))); // minus one day
  15.         }
  16.            
  17.  
  18.         // Setup search array
  19.         $args = array();
  20.            
  21.         if($search != " "){ $args['s'] = $search;  }
  22.        
  23.         if($venue){ $args['venue'] = (int)$venue; }
  24.        
  25.         if($s_date){ $args['start_date'] = $s_date; $args['end_date'] = $e_date; }
  26.        
  27.         $args['posts_per_page'] = 5;
  28.        
  29.         $args['eventDisplay'] = 'upcoming';
  30.            
  31.         $args['paged'] = $paged;
  32.        
  33.        
  34.         if ($tax_slug == "all") {
  35.            
  36.             $events = tribe_get_events($args);
  37.            
  38.            
  39.         } // end if
  40.         else {
  41.            
  42.             $args['tax_query'] = array(
  43.                                     array(
  44.                                         'taxonomy' => 'tribe_events_cat',
  45.                                         'field' => 'slug',
  46.                                         'terms' => $tax_slug
  47.                                     )
  48.                                 );
  49.                        
  50.            
  51.             $events = tribe_get_events($args);
  52.            
  53.         } // end else
  54.        
  55.         echo '<pre style="white-space: pre-wrap;">'.print_r($args,true).'</pre>'; // debug array
  56.        
  57.        
  58.         if ($events == null){
  59.        
  60.             echo'<p>Your search returned no results, please try searching again.</p>';
  61.        
  62.         }else{
  63.        
  64.         // Events loop
  65.         foreach($events as $post) {
  66.         setup_postdata($post);
  67.         ?>
  68.             <div class="upcoming_events">
  69.                 <div class="event_date">
  70.                     <span class="calendar_month"><?php echo tribe_get_start_date( $post->ID, false, 'M' ); ?></span>
  71.                     <span class="calendar_day"><?php echo tribe_get_start_date( $post->ID, false, 'd' ); ?></span>
  72.                 </div>
  73.                 <div class="event_desc">
  74.                     <h4><a href="<?php echo tribe_event_link(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
  75.                     <?php the_excerpt(); ?>
  76.                 </div><!--event desc-->
  77.                 <div class="event_meta">
  78.                     <ul>
  79.                         <li><span>Start:</span><p><?php echo tribe_get_start_date( $post->ID, true, 'm/d/y  ' ); ?></p></li>
  80.                         <li><span>End:</span><p><?php echo tribe_get_end_date( $post->ID, true, 'm/d/y  ' ); ?></p></li>
  81.                         <?php if(tribe_has_venue()){ ?><li><span>Location:</span><p><?php echo tribe_get_venue(); ?></p></li><? } ?>
  82.                         <?php if(tribe_address_exists()){ ?><li><span>Address:</span><p><?php echo tribe_get_address(); ?><br /><?php echo tribe_get_city().', '; echo tribe_get_state().' '; echo tribe_get_zip(); ?></p></li><?php } ?>
  83.                         <?php if(tribe_get_cost() != ""){ ?><li><span>Cost:</span><p><?php echo tribe_get_cost(); ?></p></li><?php } ?>
  84.                     </ul>
  85.                 </div><!--event meta-->
  86.             </div><!--upcoming events-->
  87.            
  88.    
  89.        
  90.         <?php } // end foreach
  91.        
  92.          } // end else
  93.          ?>
Advertisement
Add Comment
Please, Sign In to add comment