List Upcoming & Past Events at /events

Home Forums Calendar Products Events Calendar PRO List Upcoming & Past Events at /events

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #495565
    David Kelly
    Participant

    Is there any way to include past events, along with upcoming events on the main Events page (/events)?

    At the moment visiting “/events” shows the one upcoming event scheduled, along with a link to “Previous Events”. I would like that page to display past events under any scheduled upcoming events (as with a normal loop).

    Thanks,

    David

    #506149
    Barry
    Member

    Hi David,

    Though a bit rough and ready this snippet (which you could for instance add to your theme’s functions.php file) should give you an idea as to how you might approach this:

    add_action( 'tribe_events_after_loop', 'add_past_events' );
    
    function add_past_events() {
    	if ( ! tribe_is_list_view() || ! tribe_is_upcoming() ) return;
    	remove_action( 'tribe_events_after_loop', 'add_past_events' );
    
    	$past_events = tribe_get_events( array(
    		'eventDisplay' => 'past'
    	) );
    
    	foreach ( $past_events as $event )
    		echo "$event->post_title - $event->EventStartDate <br/>";
    }

    Does that help at all?

    #523613
    David Kelly
    Participant

    Thanks Barry,

    That gets me a little closer, but it’s causing an issue with the “Previous Events” pagination link at the bottom of the page – when I click on that, the past events (created in $past_events) are repeated.

    Is there any way to display both upcoming & past events in the same loop? I will need to do the same thing for the Event Categories too.

    Thanks,

    David

    #527453
    Barry
    Member

    Hi David!

    That was really just a starting point – you might tweak and further build on it and use helpers like tribe_is_past() to avoid repeating it on the past events page.

    Is there any way to display both upcoming & past events in the same loop? I will need to do the same thing for the Event Categories too.

    It’s possible for sure – but I’m afraid that sort of customization is a bit beyond what we can help you with here on the forum. Some good WP coding knowledge would definitely be required (and you’d probably be interested in filter hooks like parse_query and pre_get_posts here).

    Good luck 🙂

    #723592
    Barry
    Member

    Hi! It’s been a while so I’m going to go ahead and close this thread. If we can help with anything else, though, please don’t hesitate to create new threads as needed. Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘List Upcoming & Past Events at /events’ is closed to new replies.