Sorting sub-array in descending order using Groq in Sanity.io.

6 replies
Last updated: Mar 14, 2023
Is there a way I can sort a sub-array from my response?
I want the adventureBlogPosts to be sorted in descending order, however it doesn’t seem to flip order when I change “desc” to “asc”
still a groq noob here, but might be that you want the pipe and order() fn to live after the last curly brace that you have highlighted there - order of operations can matter sometimes on these
thanks User, will give it a shot now
❤️ that did it, would never have thought to put it there
thank you thank you!
yeah, was floating around in my head due to a part of the kap+lauren learn groq youtube playlist where they went over order of operations on some stuff, this type of thing is always so annoying and tricky with new languages but glad it worked

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?