✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Issue with article sorting by publishedAt date is resolved after a quick fix.

17 replies
Last updated: Feb 9, 2021
When fetching articles sorted by
date ordered DESC, results are somewhat jumbled with some of the articles that should be at the end of the list are being inserted at the beginning. The results in the screenshot start with the latest articles: 2021, then 2019 then 2021 again.
Feb 9, 2021, 10:16 AM
Thanks for reporting, Alex! Could you try wrapping
to see if that makes a difference, even if it slows down the query?
Feb 9, 2021, 10:25 AM
Thanks for the quick response but which
do I wrap with
? Not sure where to put it.
Feb 9, 2021, 10:31 AM
Apologies, I assumed you were using GROQ here, which doesn't make sense given the channel name and screenshots you shared 😉 In that case, it'd have been like this:
order(dateTime(publishedAt) desc)
. Not here though.
We'll try to reproduce the issue on our end.
Feb 9, 2021, 10:34 AM
I see. I hope this get resolved soon. It's breaking the pagination of our site.
Feb 9, 2021, 10:37 AM
Could you add the document IDs to the query to verify that these are all published documents, including the ones that wrongly show up in the list?
Feb 9, 2021, 10:38 AM
Also, are you seeing correct results when ordering by
Feb 9, 2021, 10:38 AM
Here with

Yes, results seem to be accurate when ordered by
Feb 9, 2021, 10:42 AM
Interestingly, the articles jumbled in seems to be the ones I migrated from Wordpress with their own custom
Feb 9, 2021, 10:43 AM
But that shouldn't affect the order, right?
Feb 9, 2021, 10:44 AM
Woops, wrong screenshots.
Feb 9, 2021, 10:46 AM
That's odd indeed. It shouldn't affect the order, but it does stand out that these have timestamps ending on 000Z, which perhaps were set slightly differently even if the distinction between the two doesn't surface in these results.
Could you compare an imported article with one of the others and check if their
values have identical formats when inspecting their raw JSON in the studio?
Feb 9, 2021, 10:54 AM
Some of the imported articles'
were manually set using Sanity's built-in datepicker.
Feb 9, 2021, 11:17 AM
You can see the jumbled results here https://opinyon.net/sections/opinion and here
Everything was fine yesterday though. The imported articles were imported 2 weeks ago and we haven't made any changes with our queries since then.
Feb 9, 2021, 11:21 AM
Thanks for the additional details Alex. I can confirm that this is a regression on our side, and the back-end team are looking into it. Started late yesterday/early today. Will keep you updated here.
Feb 9, 2021, 11:45 AM
I see. I guess I'll sort by
at the moment. Thank you for help.
Feb 9, 2021, 11:48 AM
Hi again Alex, our back-end team just pushed a fix to production that should resolve these ordering issues on datetime fields. Please let me know if ordering by
now works properly.
Feb 9, 2021, 3:23 PM
Hi Peter, it's now working fine again. Thank you for the swift fix!
Feb 9, 2021, 7:43 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?