Get the categories/subcategories an author has written for
Author Query
export const authors = groq`
*[_type == 'author' && slug.current == $slug && archived == false][0]{
_id,
_updatedAt,
name,
'slug': slug.current,
role,
image,
bio,
socialMedia,
}
`Author Categories Query
*[_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.
Contributors

James Singleton
Senior Software Engineer at AmEx

Alexander Staubo
Backend developer at Sanity.io