Everything *[NYC] 2026: see what we announced.

Get the categories/subcategories an author has written for

By James Singleton & Alexander Staubo


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

James Singleton

Senior Software Engineer at AmEx

Visit James Singleton's profile
Alexander Staubo

Alexander Staubo

Backend developer at Sanity.io

Visit Alexander Staubo's profile