How to show Previous Events if there are no Upcoming Events

Home Forums Calendar Products Events Calendar PRO How to show Previous Events if there are no Upcoming Events

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #159778
    simoncarr
    Participant

    Hi,

    I’m using a custom php template to pull in some events. Code below..

    Is there a way to code this so the 3 most recent past events show up if there are no upcoming events? Any help would be appreciated, thanks!

    <?php
    global $post;
    $all_events = tribe_get_events(
    array(
    ‘eventDisplay’=>’upcoming’,
    ‘posts_per_page’=>3,
    )
    );
    foreach($all_events as $post) {
    setup_postdata($post);
    ?>

    #160904
    Barry
    Member

    Hi! Could you check the result to see if any posts were retrieved first time round ($all_events->have_posts() or else check the post_count property) then if it is apparent nothing was retrieved, run a new query but set eventDisplay to past?

    #163706
    simoncarr
    Participant

    Barry,

    Sorry – I’m not sure I follow what you are saying. Can you show me how you would structure that code?

    Thanks

    #165941
    Barry
    Member

    Apologies, I forgot you don’t actually get a WP_Query object back when you use tribe_get_events(). Even so, you should receive an array as the result – so perhaps you could do something like:

    $events = tribe_get_events( $your_original_query );
    
    // Check if any events were returned
    if ( count( $events ) > 0 ) {
        // Your code to display the results
    }
    else { 
        $events = tribe_get_events( $your_past_event_query );
        // Display past events instead...
    }

    Does that help?

    #168249
    consoleoffice
    Participant

    How can I remove the section of “Upcoming Events” completely?

    Thanks.

    #723200
    Barry
    Member

    Hi: I’m very sorry we missed these follow up questions. That was, unfortunately, due to a bug in our forum software (which only notified us of updates when the original poster added a new reply). Owing to the amount of time that’s elapsed I will now close this thread and I’d ask that if you still need help you create a fresh thread: one of the team will then be only too happy to assist 🙂

    Thanks!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘How to show Previous Events if there are no Upcoming Events’ is closed to new replies.