Show a calculated range of pages

Hi,

is ist possible to show a calculated range of pages?

Example:
I have a page with a field called “year”. I need to display all pages with the same year +/- 10 years.

I already managed it to display pages with the same year with the following line:

<?php $werke = page('bibliothek/werke')->children()->filterBy('year',$page->year()->uri());?>

Yes, you can do that with a filter with a callback

https://getkirby.com/docs/cheatsheet/pages/filter

More date based examples here: https://getkirby.com/docs/cookbook/filtering

almost there…

but with this i get no results:

<?php $werke = page('bibliothek/werke')->children()->filterBy('year', '>', strtotime('year - 10'))->filterBy('year', '<', strtotime('year + 10'));?>

(i have set the field as number)

That doesn’t make sense

Sorry, i´m still super confused and can´t make it work so far:

the year is

<?= $page->date('Y', 'year')?>

and the calculation is:

$werke = $page('bibliothek/werke')->children()->filterBy('year', '>', strtotime('-10 years'))->filterBy('year', '<', strtotime('+10 years'));

Where am i wrong?

As I said above, you have to use a filter with a callback, not filterBy(). Currently, you are comparing the year field (which in this case probably returns a string) to a unix timestamp. But you have to convert your field value to a Unix timestamp to be able to compare it to another Unix timestamp.

The examples in the cookbook recipe should help (sorry, posted the wrong link above).