List all events and sort by latest date

Home Forums Calendar Products Events Calendar PRO List all events and sort by latest date

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12039
    Terrance
    Member

    Hi,
    I’m able to use WP_Query to list out all the event in the event list. How can I sort them by the latest date. What is the parameter for orderby, or is there any better way of listing all events?

    Thanks in advance.

    #12057
    Rob
    Member

    We should be able to help you with this. I’ll get Jonah to comment directly.

    #12078
    Jonah
    Participant

    If you are working with WP_Query you should be able to use all parameters available to it. However, I would suggest using the plugin native function tribe_get_events instead because if you’re trying to orderby with WP_Query it’s going to order by the published date and not the date of the events.

    To query using tribe_get_events you would do something like this:

    global $post;
    $all_events = tribe_get_events( array('eventDisplay'=>'all', 'posts_per_page'=>-1) );
    foreach($all_events as $post) : setup_postdata($post);
    echo '';
    the_title();
    echo '
    ';

    if ( has_post_thumbnail() ) {
    echo '<a href="';
    the_permalink();
    } else {
    echo the_excerpt();
    }
    endforeach;

    You can change eventDisplay to ‘past’, ‘upcoming’, ‘day’, ‘all’ or ‘month’ and then you can still use all the other parameters available with WP_Query.

    Hope that helps,
    Jonah

    #12100
    Terrance
    Member

    Thanks! Jonah. Got it working.

    #12131
    Jonah
    Participant

    Glad to hear! Let us know if you need anything else.

    #974882
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘List all events and sort by latest date’ is closed to new replies.