Don’t get it with my year filter made from a date field

Hey there.

I have 3 Filters on the same page and with your help and some hours of bleeding, I got them running. I’m so happy. The last thing I want, is to reduce the years filter to actually years and pluck them together, so that the visitor can choose a year and the page spits out all posts within that year. This the specific page on the Staging-Site. May be this is helpfull.

I «studied» these 2 pages but this is all to heavy for me:

This is what I have ↓. What do I have to rebuild? See the marked blocks.

  $ar_Filter = get('artistfilter');
  $lo_Filter = get('locationfilter');
  $ye_Filter = get('yearfilter');

  $unfiltered = $page->children()->listed()->filterBy('front', false);

  $exhibitions = $unfiltered
  ->when($ar_Filter, fn ($ar_Filter) => $this->filter(fn ($item) => $item->artists()->toPages(',')->findBy('title', $ar_Filter)))
  ->when($lo_Filter, fn ($lo_Filter) => $this->filter(fn ($item) => $item->locations()->toPages(',')->findBy('title', $lo_Filter)))

  // 🔻
  ->when($ye_Filter, function ($ye_Filter){
    return $this->filterBy('date', $ye_Filter);
  // 🔺

  ->sortBy(function ($page) {
    return $page->date()->toDate();

  $a_filters = $unfiltered->pluck('artists', ',', true); 
  $l_filters = $unfiltered->pluck('locations', ',', true); 
  // 🔻
  $y_filters = $unfiltered->flip()->pluck('date', null, true);
  // 🔺

  <?php foreach($y_filters as $jahr): ?>
    <a href="<?= $page->url() ?>?yearfilter=<?= $jahr->date() ?>"><?= $jahr->date() ?></a>
  <?php endforeach ?>

<!-- 👇 only for completeness -->
  <?php $artists = page('artists')->children()->filterBy('id', 'in', $a_filters); ?>
  <?php foreach($artists as $artist): ?>
    <a href="<?= $page->url() ?>?artistfilter=<?= $artist->title() ?>"><?= $artist->title() ?></a>
  <?php endforeach ?>
  <?php $locations = page('locations')->children()->filterBy('id', 'in', $l_filters); ?>
  <?php foreach($locations as $location): ?>
    <a href="<?= $page->url() ?>?locationfilter=<?= $location->title() ?>"><?= $location->title() ?></a>
  <?php endforeach ?>
  ->when($ye_Filter, function ($ye_Filter) {
    return $this->filter(fn ($item) => $item->date()->toDate('Y') === $ye_Filter);

Now I extended my pluck like your hint on Pluck datefields - #7 by TakioTk like this:

$y_filters = $unfiltered->flip()->pluck('date', null, true);
$y_filters = array_unique(array_map(function($item) {
  return date('Y', strtotime($item));
}, $y_filters));

and the filter menu like this:

<?php foreach($y_filters as $year): ?>
  <a href="<?= $page->url() ?>?yearfilter=<?= $year ?>"><?= $year ?></a>
<?php endforeach ?>

Thank you very much!