Filter by date (hide past entries)

I have a simple event calendar which I only want to show the upcoming dates. I’ve tried some of the filter solutions suggested in the forum but keep on getting errors.

How do I correctly add a filter to the following query?

$entries = $calPage ? $calPage->children()->unlisted()->sortBy('calendar_event_date', 'aesc') : null;

You need to add filterBy() and then filter by date, see also Filtering collections | Kirby CMS

Filter before sorting

Fab, “date >=” was catching me out. I have it working now :slight_smile:

$today = date('Y-m-d');

$entries = $calPage ? $calPage->children()->unlisted()->filterBy('calendar_event_date', 'date >=', 'today')->sortBy('calendar_event_date', 'aesc') : null;