Is there a way to sort by a number field that lives within a group?
For example, I want to set a different order for the content depending on its value for that "service":
Is there a way to sort by a number field that lives within a group?
For example, I want to set a different order for the content depending on its value for that "service":
Are you using GraphQL or the REST API? You will be able to sort on the client side.
Rest API — so you’d have to load all posts then sort?
Hi @jason, there isn’t any way to sort the order of items in a Group field via the API. It will always return the order of the items as they are set in the Prismic UI.
If you want to sort the Group field items by anything other than their order in the UI, then (as @marcellothearcane mentioned) you can sort them on your end after running the query.
I think I’ve miscommunicated. I want don’t want to sort the items in the group, I want to be able to sort the parent content type by the group’s particular order.
For example, we have a content type called “project”, and each project has a group of services. On the website, when viewing the list of projects — filtered by the service group — I want the projects to be in a different order for that service, than they’d appear in other services.
Pseudo code: [service['ecommerce']['order'] desc]
Hi @jason, thanks for the clarification. Unfortunately it isn’t possible to order the Prismic results based on a field inside of a Group as you’ve described. This will need to be something that you do on your side after running the query for all the projects.
But I will tag the @features-team here so they can see your use case and add this to our feature request tracker as a possible improvement for the future.
This is being tracked as an open feature request.
If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the button to show your support for the feature and check out our Feature Request Guidelines.