I’m trying to filter the pages of my website by year. As far as I know I can’t get the creation date of a page but I can get the modification date, which is fine (if not better) for my usecase.
I’m trying to set up a counter that would count the amount of page created this year / the total amount of pages
So I’m trying to filter the pages of my website by modification and it keeps returning 0 here, no matter what I try…
<?php $year = date('Y');
echo $year;
echo $page->modified("Y-m-d") ?>
<?= $pages->filterBy('modified', '>', '2024-01-01')->filterBy('modified', '<', '2025-01-01')->count(); ?>
Is there a way to do it?
Thanks!
modified returns a timestamp, so you need to compare to timestamps instead of date strings.
You can create a field in your page blueprint that stores the date of page creation.
created:
type: date
default: today
disabled: true
Then optionally use the blueprint create option:
create:
fields:
- created
maybe it will also help you if you want to filter both
php code:
pages('page_id')->children()->listed()->filterBy('modified', 'date >', '0000-00-00 00:00:00');
pages('page_id')->children()->listed()->filterBy('created', 'date >', '0000-00-00 00:00:00');