0

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.

  • You should use sql query to accomplish this. The default wordpress way will need a lot more queries and will be very complicated. The downside of using custom sql query is that you can't use the loop and create the pagination yourself. – sakibmoon May 29 '15 at 21:02
0

I think It's complicated so I prefer make an alternative for the organisation of my website. I will create a page futur events and a page past events.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.