'aec_events', 'posts_per_page' => empty( $events_settings['events_per_page'] ) ? -1 : $events_settings['events_per_page'], 'order' => $events_settings['order'], 'paged' => $paged, 'post_status' => 'publish', 's' => $search_query, ); $meta_queries = array(); $tax_queries = array(); if( ! empty( $_GET['venue'] ) ) { $meta_queries[] = array( 'key' => 'venue_id', 'type' => 'NUMERIC', 'compare' => '=', 'value' => (int) $_GET['venue'], ); } if( ! empty( $_GET['cat'] ) ) { $tax_queries[] = array( 'taxonomy' => 'aec_categories', 'field' => 'term_id', 'terms' => (int) $_GET['cat'], ); } if( ! empty( $_GET['date'] ) ) { $meta_queries[] = array( 'key' => 'start_date_time', 'type' => 'DATETIME', 'compare' => 'LIKE', 'value' => sanitize_text_field( $_GET['date'] ), ); } if( ! empty( $_GET['from'] ) && isset( $_GET['to'] ) ) { $meta_queries[] = array( 'key' => 'start_date_time', 'type' => 'DATETIME', 'compare' => '>=', 'value' => sanitize_text_field( $_GET['from'] ), ); $meta_queries[] = array( 'key' => 'start_date_time', 'type' => 'DATETIME', 'compare' => '<=', 'value' => sanitize_text_field( $_GET['to'] ), ); } switch( $events_settings['orderby'] ) { case 'date': $args['orderby'] = 'date'; break; case 'title': $args['orderby'] = 'title'; break; case 'event_start_date': $args['meta_key'] = 'start_date_time'; $args['orderby'] = 'meta_value_datetime start_date_time'; break; } if( empty( $general_settings['show_past_events'] ) ) { $meta_queries[] = array( 'relation' => 'OR', array( 'key' => 'start_date_time', 'value' => current_time('mysql'), 'compare' => '>=', 'type' => 'DATETIME' ), array( 'key' => 'end_date_time', 'value' => current_time('mysql'), 'compare' => '>=', 'type' => 'DATETIME' ) ); } $count_meta_queries = count( $meta_queries ); if( $count_meta_queries ) { $args['meta_query'] = ( $count_meta_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $meta_queries ) : array( $meta_queries ); } $count_tax_queries = count( $tax_queries ); if( $count_tax_queries ) { $args['tax_query'] = ( $count_tax_queries > 1 ) ? array_merge( array( 'relation' => 'AND' ), $tax_queries ) : array( $tax_queries ); } $aec_query = new WP_Query( $args ); if( $aec_query->have_posts() ) { global $post; ob_start(); include AEC_PLUGIN_DIR."public/partials/events/aec-public-events-$view-display.php"; return ob_get_clean(); } else { return __( 'Sorry, no results matched your criteria.', 'another-events-calendar' ); } } }