Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Limit events to upcoming only
- */
- function event_listings( $query ) {
- $path = get_current_path();
- if( ( $path['exploded'][1] === 'clubs' ) && ( $path['exploded'][3] === 'events' ) ) {
- $club_specific_event_archive = TRUE;
- } elseif( ( $path['exploded'][1] === 'koru-lounge' ) && ( $path['exploded'][2] === 'events' ) ) {
- $koru_lounge_event_archive = TRUE;
- }
- if( ( $query->is_main_query() ) && ( !is_admin() ) && ( ( is_post_type_archive( 'event_post' ) ) || ( ( $club_specific_event_archive == TRUE ) || ( $koru_lounge_event_archive == TRUE ) ) ) ) {
- $today = date("Y-m-d",strtotime("today"));
- if( ( $club_specific_event_archive == TRUE ) || ( $koru_lounge_event_archive == TRUE ) ) {
- if( $koru_lounge_event_archive == TRUE ) {
- $meta_value = $path['exploded'][1];
- } else {
- $meta_value = $path['exploded'][2];
- }
- $meta_value = ucwords( str_replace( "-", " ", $meta_value ) );
- $venue_specific = array(
- 'key' => '_event_venue',
- 'value' => $meta_value,
- 'compare' => 'LIKE'
- );
- $query->set( 'is_page', '' );
- $query->set( 'is_singular', '' );
- }
- $meta_query = array(
- array(
- 'key' => '_event_date',
- 'value' => $today,
- 'compare' => '>=',
- ),
- $venue_specific
- );
- $query->set( 'meta_query', $meta_query );
- $query->set( 'post_status', 'publish' );
- $query->set( 'meta_key', '_event_date' );
- $query->set( 'orderby', 'meta_value' );
- $query->set( 'order', 'ASC' );
- $query->set( 'ignore_sticky_posts', 1 );
- // echo "<pre>"; print_r( $query ); echo "</pre>";
- }
- }
- add_action( 'pre_get_posts', 'event_listings' );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement