Event future dates only?

I’ve followed the tutorial to create an events section on the website:

I’ve added a sort by to place the events in order:
$events = $EventsPage->children()->listed()->sortBy(‘from’, ‘asc’);

I would like previous events to today to not show, I’m not sure how to filter this as there are so may posts about it, but none are clear enough based on the tutorial example.

I have tried out the cookbook in a fresh starter kit.
With the following change, only the future events are output:

/site/templates/events.php
// before
$events = $page->children()->listed();
if ($events->count() > 0): ?>
// after
$events = $page->children()->filter(function ($child) {
return $child->to()->toDate() > time();
});
if ($events->count() > 0): ?>

And if you want the current event to be displayed first, add flip().

$events = $page->children()->filter(function ($child) {
return $child->to()->toDate() > time();
})->flip();
if ($events->count() > 0): ?>

1 Like

this plugin might also help in filtering dates.

Thank you so much, that worked great!

1 Like