Surjith S M
Web Designer & Front-end Developer. Figma, TailwindCSS & Next.js
This snippet will return only matched item in a sub array inside a document
// 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.
Web Designer & Front-end Developer. Figma, TailwindCSS & Next.js
Suppose you have an Array Reference to Category and you want to get all posts with one of the categories listed in the current post. This is usually when you need to get related items.
Go to Get related items of a post in sanity by comparing category array reference with another arrayA short snippet to filter category, tags or other document based on total referenced count.
Go to Sanity GROQ Filter category by highest reference count in other documentsSnippet for `internalLInk` Reference in GROQ and rendering it in React/Next.js frontend using Portabletext.
Go to Sanity internalLink render in React with Portable TextSanity preview component cannot access the parent/document if its inside an array or object. Using Custom Preview component, we can solve the issue.
Go to Sanity Custom Preview Component to get Parent Document