Hello Stephen. I’m dropping a few links below. The site is visitplacer.com. If you go to for example https://www.visitplacer.com/things-to-do/arts-culture/ you can see an ajax call where I’m loading in more posts. It works perfectly.
But I just noticed that it doesn’t work for events. https://www.visitplacer.com/events/
Instead of pulling in the next page of events…it pulls in old events. I’m dropping a gist below also with the relevant code I’m using.
https://gist.github.com/zzramesses/ae378d4c356ecc0bc3cee4bf3a038655
Ali Zamanian
Hi Ali,
I suspect it might be ordering by publication date rather than event date. Try adding
'orderby' => 'eventstart',
'order' => 'ASC',
to the query
Stephen Harris
Hey Stephen. The code that the ajax action is hitting is below. You were right that it was returning them in post ID order(pub date). I tried your suggestion and they are still coming back in pub date order.
function ajax_events_load_more() {
$args = isset( $_POST[‘query’] ) ? array_map( ‘esc_attr’, $_POST[‘query’] ) : array();
$args[‘paged’] = esc_attr( $_POST[‘page’] );
$args[‘orderby’] = ‘eventstart’;
$args[‘order’] = ‘ASC’;
$args[‘suppress_filters’] = false;
$args[‘post_status’] = ‘publish’;
ob_start();
$loop = new \WP_Query( $args );
if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post();
get_template_part( 'partials/event', 'list' );
endwhile; endif; wp_reset_postdata();
$data = ob_get_clean();
wp_send_json_success( $data );
wp_die();
}
Ali Zamanian
I’ll try that on a test install today, but that does look correct.
Stephen Harris