Joint session with Vercel: How to build intelligent storefronts (May 15th)

Sanity groq Filter by item in an array

This snippet will return only matched item in a sub array inside a document

By Surjith S M


return only matched variant


// Returns variant name matched in variant[] array

*[_type == "products" && slug.current == $slug][0] {
    variant[type match $variant][0]{
        ...
      }
  }
  
  
  
// Params

{
   "slug": "slug",
   "variant": "variant"
}

This query will help you to filter a document based on an item match inside an array inside the document.

Contributor

Surjith S M

Web Designer & Front-end Developer. Figma, TailwindCSS & Next.js

India

Visit Surjith S M's profile