Trying to figure out how to filter from last date in structure field.
Went trough some topics but im still not able to find it.
playtime:
label: playtime
type: structure
fields:
title:
label: Event title
type: text
eventdate:
label: Event date
type: date
location:
label: Event location
type: text
<?php
$items = page('archief')->children()->filter(function($child) {
$structure = $child->playtime()->toStructure();
return $structure->date('eventdate')->toDate() > time();
});
?>
So you only want dates in the future, sorted by date?
Not tested, but something like this should work:
<?php
$items = page('archief')->children()->filter(function($child) {
$structure = $child->playtime()->toStructure();
return $structure->filter(function($item) {
return $item->eventdate()->toDate() > time();
});
});
its now showing all the children, future and past. Even the ones that have no date attached yet in the field.
Is this Kirby 2 or 3? Please change your post topic accordingly.
Maybe we need a boolean here:
<?php
$items = page('archief')->children()->filter(function($child) {
$structure = $child->playtime()->toStructure();
return $structure->filter(function($item) {
return $item->eventdate()->toDate() > time();
})->count();
});
Yes now it works! so adding the ->count() did the trick?
Got to love the Kirby Team!
Thanks for the patience with newbies!
Yes, it returns false if the structure field doesn’t contain any items with an event date in the future.