Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda