I show a structure with dates involved. I like to only show future entries. After following this thread I thought I could use the same, but I get the error “Object of class Kirby\Cms\Field could not be converted to int” so it has to do with the dates being international… I have a multilanguage setup and use 'date.handler' => 'intl' in my config. I’m not fluent in php so I’m a bit lost now.
This is my code:
foreach ($productions as $production):
$items = $production->playdates()->toStructure()->filterBy('playdate','>',strtotime('now'))->sortBy('playdate', 'desc');
foreach ($items as $item): ?>
<li>
<span><?= $item->playdate()->toDate('EEEE d MMMM Y – H:mm') ?></span>
<span><?= $production->title() ?></span>
<span><?= $item->location() ?></span>
<span><?= $item->city() ?></span>
<?php if ($item->ticketlink()->isNotEmpty()): ?>
<a href="<?= $item->ticketlink() ?>">tickets</a>
<?php endif ?>
</li>
<?php endforeach ?>
<?php endforeach ?>
Originally I had this as well, but there was nothing rendered. When I omitted the filterBy part all entries showed up. Then I tried both time() and strtotime() as I thought it was language related, but I’ve misread the “int” for “intl” so it’s not language related…
this is how the blueprint and content of those playdates look like:
blueprint
label: Playdates
type: structure
fields:
playdate:
type: date
time: true
location:
type: text
city:
type: text
ticketlink:
type: url
You rock! Seriously, the Kirby support is so helpful in contrast to others!
As always your solution works. I didn’t know about the filter(fn($item)) method. Still scratching the surface