James Singleton
Senior Software Engineer at Zendesk
export const authors = groq`
*[_type == 'author' && slug.current == $slug && archived == false][0]{
_id,
_updatedAt,
name,
'slug': slug.current,
role,
image,
bio,
socialMedia,
}
`
*[_id == $authorId][0] { "subcategories": array::unique(*[_id in *[_type == "post" && references(^.^._id)].subcategory._ref])[] { _id, "path": "/news/" + parent->.slug.current + "/" + slug.current, title } }
I wanted to create a query that would allow me to get all of the categories/subcategories that an author had written for so that I could display them on their author page.
To be somewhat more performant, I pass the $authorId
instead of query for the author all over again as I already queried for that information prior.
Senior Software Engineer at Zendesk
Backend developer at Sanity.io
If you want to pass a parameter to a query that might not always be defined
Go to Handle Certain Values To Be TrueSuppose 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 arrayThis can be used for blogs or articles where you want to possibly display next and previous article buttons
Go to Get current post, previous post, and next post