Surjith S M
Web Designer & Front-end Developer. Figma, TailwindCSS & Next.js
It will expand the reference (projection) which is deeply linked in an array and optional using select funtion.
// Using (select)
// https://www.sanity.io/docs/groq-functions#298e89c3c8d9
*[_type == "page" && slug.current == $slug][0] {
...,
content[] {
...,
select( _type == "pricing" ) => {
plan[]->
},
}
}
// Short Form
// Also works without select()
*[_type == "page" && slug.current == $slug][0] {
...,
content[] {
...,
_type == "pricing" => {
plan[]->
},
}
}
// Params
{
"slug": "slugname"
}
Imagine you have a document with deeply linked arrays. Inside that, you have a reference that might or might not appear. You have to expand that reference using projection ->
but the problem is it doesn't appear on every array. it's completely optional.
This snippet will expand the reference which is deeply linked in an array and optional using the select
function.
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