Query posts with specific author in second position of multiple authors

19 replies
Last updated: Nov 29, 2025
Lets say i have "Posts" and i have "Authors" which is multiple authors for a post. Is it possible to do a query for "Give me all posts that are written by more than one author, where Chris is the second author" (as mentioned in the"shoptalkshow") ? What does that query look like ?
AI Update

Yes! This is absolutely possible in GROQ. You can access array elements by their index position and filter on specific positions within an array.

Here's how you would write that query:

*[_type == "post" && count(authors) > 1 && authors[1]->name == "Chris"]

Let me break down what's happening:

  1. count(authors) > 1 - Filters for posts with more than one author
  2. authors[1] - Accesses the second element in the authors array (arrays are zero-indexed, so [1] is the second position)
  3. ->name == "Chris" - Dereferences the author reference and checks if the name equals "Chris"

If you want to return specific fields from the matching posts, you can add a projection:

*[_type == "post" && count(authors) > 1 && authors[1]->name == "Chris"]{
  title,
  authors[]->{name}
}

A few important notes:

  • Array indexing is zero-based: authors[0] is the first author, authors[1] is the second, etc.
  • The -> operator dereferences the reference to get the actual author document
  • You can chain conditions: Combine multiple filters with && to get exactly what you need

If your authors array contains objects rather than references, you'd adjust slightly:

*[_type == "post" && count(authors) > 1 && authors[1].name == "Chris"]

This pattern works for any array position - just change the index number to match the position you're interested in!

Show original thread
19 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?