Skip to content
● Critical PHP security fixes are out: update PHP on your Grav sites. What to do →

page.date != page.header.date, now my collection sorting is broken (bug? by design?)

Solved by Anna View solution

Started by Anna 19 hours ago · 1 replies · 38 views
19 hours ago

I just migrated one of my old sites to Grav 2 (went without a hitch, I love the migration wizard). However, there’s a news page which orders its children by page date descending.

This is the code that used to work:

TWIG
{% set collection = page.collection({'items':{'@self.children': ''},'order': {'by': 'date', 'dir': 'desc'}}) %}
{% for p in collection %}
  (output other details)
  {{ p.date|date("d.m.Y") }}
{% endfor %}

What happens now is that every date is output as today’s. I did some dumps:

{{ vardump(collection) }} shows the timestamp of this morning, 11:30, which is the time I downloaded all the content from the live version to tinker with.

It seems to me that maybe page.date has always referred to the file’s creation date, and not page.header.date – but nobody noticed before because that was usually the same thing. Can someone confirm that’s how it’s meant to be?

That would mean that I cannot sort by page.date if I want to refer to page.header.date, but also sorting by page.header.date sorts alphanumerically, which is not what I want either. What is the best solution here?

last edited 10/26/26 by Anna
18 hours ago Solution

Found the problem: there were more than a page of articles that had no date set in the header, and of course those got the fallback of page creation date. The others are working fine, it just took me a moment to find them on the later pages…

Sorry for the confusion folks!

Suggested topics

Topic Participants Replies Views Activity
Support · by webmasterodp, 3 weeks ago
4 266 2 weeks ago
Support · by nwhitfield, 3 weeks ago
2 230 3 weeks ago
Support · by stell, 4 weeks ago
5 481 3 weeks ago
Support · by gravinator, 2 months ago
5 657 3 weeks ago
Support · by Gravver, 1 month ago
6 441 1 month ago