uery_vars['scope'] = 'all'; //otherwise we'll get 404s for past events } }else{ $scope = $wp_query->query_vars['scope']; } } if ( $scope == 'today' || $scope == 'tomorrow' || preg_match ( "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $scope ) ) { $EM_DateTime = new EM_DateTime($scope); //create default time in blog timezone if( get_option('dbem_events_current_are_past') && $wp_query->query_vars['post_type'] != 'event-recurring' ){ $query[] = array( 'key' => '_event_start_date', 'value' => $EM_DateTime->getDate() ); }else{ $query[] = array( 'key' => '_event_start_date', 'value' => $EM_DateTime->getDate(), 'compare' => '<=', 'type' => 'DATE' ); $query[] = array( 'key' => '_event_end_date', 'value' => $EM_DateTime->getDate(), 'compare' => '>=', 'type' => 'DATE' ); } }elseif ($scope == "future" || $scope == 'past' ){ $EM_DateTime = new EM_DateTime(); //create default time in blog timezone $EM_DateTime->setTimezone('UTC'); $compare = $scope == 'future' ? '>=' : '<'; if( get_option('dbem_events_current_are_past') && $wp_query->query_vars['post_type'] != 'event-recurring' ){ $query[] = array( 'key' => '_event_start', 'value' => $EM_DateTime->getDateTime(), 'compare' => $compare, 'type' => 'DATETIME' ); }else{ $query[] = array( 'key' => '_event_end', 'value' => $EM_DateTime->getDateTime(), 'compare' => $compare, 'type' => 'DATETIME' ); } }elseif ($scope == "month" || $scope == "next-month" || $scope == 'this-month'){ $EM_DateTime = new EM_DateTime(); //create default time in blog timezone if( $scope == 'next-month' ) $EM_DateTime->add('P1M'); $start_month = $scope == 'this-month' ? $EM_DateTime->getDate() : $EM_DateTime->modify('first day of this month')->getDate(); $end_month = $EM_DateTime->modify('last day of this month')->getDate(); if( get_option('dbem_events_current_are_past') && $wp_query->query_vars['post_type'] != 'event-recurring' ){ $query[] = array( 'key' => '_event_start_date', 'value' => array($start_month,$end_month), 'type' => 'DATE', 'compare' => 'BETWEEN'); }else{ $query[] = array( 'key' => '_event_start_date', 'value' => $end_month, 'compare' => '<=', 'type' => 'DATE' ); $query[] = array( 'key' => '_event_end_date', 'value' => $start_month, 'compare' => '>=', 'type' => 'DATE' ); } }elseif ($scope == "week" || $scope == 'this-week'){ $EM_DateTime = new EM_DateTime(); //create default time in blog timezone list($start_date, $end_date) = $EM_DateTime->get_week_dates( $scope ); if( get_option('dbem_events_current_are_past') && $wp_query->query_vars['post_type'] != 'event-recurring' ){ $query[] = array( 'key' => '_event_start_date', 'value' => array($start_date,$end_date), 'type' => 'DATE', 'compare' => 'BETWEEN'); }else{ $query[] = array( 'key' => '_event_start_date', 'value' => $end_date, 'compare' => '<=', 'type' => 'DATE' ); $query[] = array( 'key' => '_event_end_date', 'value' => $start_date, 'compare' => '>=', 'type' => 'DATE' ); } }elseif( preg_match('/(\d\d?)\-months/',$scope,$matches) ){ // next x months means this month (what's left of it), plus the following x months until the end of that month. $EM_DateTime = new EM_DateTime(); //create default time in blog timezone $months_to_add = $matches[1]; $start_month = $EM_DateTime->getDate(); $end_month = $EM_DateTime->add('P'.$months_to_add.'M')->format('Y-m-t'); if( get_option('dbem_events_current_are_past') && $wp_query->query_vars['post_type'] != 'event-recurring' ){ $query[] = array( 'key' => '_event_start_date', 'value' => array($start_month,$end_month), 'type' => 'DATE', 'compare' => 'BETWEEN'); }else{ $query[] = array( 'key' => '_event_start_date', 'value' => $end_month, 'compare' => '<=', 'type' => 'DATE' ); $query[] = array( 'key' => '_event_end_date', 'value' => $start_month, 'compare' => '>=', 'type' => 'DATE' ); } }elseif( !empty($scope) ){ $query = apply_filters('em_event_post_scope_meta_query', $query, $scope); } if( !empty($query) && is_array($query) ){ $wp_query->query_vars['meta_query'] = $query; } if( is_admin() ){ //admin areas don't need special ordering, so make it simple if( !empty($_REQUEST['orderby']) && $_REQUEST['orderby'] != 'date-time' ){ $wp_query->query_vars['orderby'] = sanitize_key($_REQUEST['orderby']); }else{ $wp_query->query_vars['orderby'] = 'meta_value'; $wp_query->query_vars['meta_key'] = '_event_start_local'; $wp_query->query_vars['meta_type'] = 'DATETIME'; } $wp_query->query_vars['order'] = (!empty($_REQUEST['order']) && preg_match('/^(ASC|DESC)$/i', $_REQUEST['order'])) ? $_REQUEST['order']:'ASC'; }else{ if( get_option('dbem_events_default_archive_orderby') == 'title'){ $wp_query->query_vars['orderby'] = 'title'; $wp_query->query_vars['order'] = get_option('dbem_events_default_archive_order','ASC'); }else{ $wp_query->query_vars['orderby'] = 'meta_value'; $wp_query->query_vars['meta_key'] = '_event_start_local'; $wp_query->query_vars['meta_type'] = 'DATETIME'; } $wp_query->query_vars['order'] = get_option('dbem_events_default_archive_order','ASC'); } }elseif( !empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == EM_POST_TYPE_EVENT ){ $wp_query->query_vars['scope'] = 'all'; if( $wp_query->query_vars['post_status'] == 'pending' ){ $wp_query->query_vars['orderby'] = 'meta_value'; $wp_query->query_vars['order'] = 'ASC'; $wp_query->query_vars['meta_key'] = '_event_start_local'; $wp_query->query_vars['meta_type'] = 'DATETIME'; } } } } EM_Event_Post::init();