Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Sanity CMS custom sorting

I don’t know if exists some way to sorting the results by custom field. My query:

 *[_type == "movies" && actors]
{
   ..., 
   isHarryMovie: name match "Harry*" 
}

So I want to sort the results by isHarry, is it posible?

I tried something like this:

 *[_type == "movies" && actors] | order(isHarryMovie asc)
{
   ..., 
   isHarryMovie: name == "Harry" 
}

and

 *[_type == "movies" && actors] | order("isHarryMovie" asc)
{
   ..., 
   isHarryMovie: name == "Harry" 
}

but they didn't work

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can order after projecting:

*[_type == "movies"] {
  ..., 
  isHarryMovie: name match "Harry*" 
} | order(isHarryMovie desc)

This will sort by the isHarryMovie attribute that you added to each document.

But this kind of query will be forced to load all the movies, then filter, and then sort — it won't be fast. You're probably better off sorting by score:

*[_type == "movies"] | score(name match "Harry*") | order(_score desc)

This will assign a high score to any movie with name match "Harry*", and a low score to everything else.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!