issue with ajax events

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 6 years, 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28994

    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
    #29007

    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
    #29016

    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
    #29026

    I’ll try that on a test install today, but that does look correct.

    Stephen Harris
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.