I need to create a loop in an event page with pagination of 10 posts per page. The way I want to do it is a little bit complicated.
For example, with current date May 1, 2015:
January 1, 2015 - March 1, 2015 - June 1, 2015 - September 1, 2015
I want to list all my events like that: (First: Future events ordered by ASC) - (After: Past events ordered by DESC)
So the final result of the loop:
June 1, 2015 - September 1, 2015 / - / March 1, 2015 - January 1, 2015
$current_date = current_time( 'timestamp', true ); $page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $wp_query = new WP_Query( array( 'post_type' => 'events', 'posts_per_page' => 10, 'orderby' => '_start_eventtimestamp', 'order' => 'ASC', 'page' => $page, 'meta_query' => array( array( 'key' => '_start_eventtimestamp', 'value' => $current_date, 'compare' => '>' ), ) ) ); if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); // THE LOOP endwhile; endif:
This code is for future events ordered by ASC, without past events. I can create another loop to get past events easily but I will get only two loops separately and it's not the result I want. And I will not get the pagination.