I’m displaying a calendar (a structure field) grouped by year, which works fine with the code underneath.
But I only need to get the entries that contain a value in the field called ‘retreat’.
<?php
$items = page('reserve')->calendar()->toStructure();
$callback = function($p) { return $p->date_end()->toDate('Y'); };
$grouped = $items->groupBy($callback)->flip();
// Group items by year
foreach ($grouped->flip() as $year => $itemsPerYear):
?>
<h2><?= $year ?></h2>
<ul>
<?php // Items date
foreach ($itemsPerYear as $item):
$start = $item->date_start()->toDate('d MMMM');
$end = $item->date_end()->toDate('d MMMM');
$date = $start . ' t/m ' . $end;
?>
<li><?= $date ?> <?= $item->retreat() ?></li>
<?php endforeach ?>
</ul>
<?php endforeach ?>