Query all authors except current article's author

13 replies
Last updated: Jan 29, 2026
How would one query for all authors and exclude the author of the current article the user is on?
AI Update

To query for all authors and exclude the author of the current article, you'd use GROQ's filter operators combined with reference comparison. Here's how:

Basic approach - if you know the author ID:

*[_type == "author" && _id != $currentAuthorId]

Within an article query using the ^ operator:

The ^ operator refers to the enclosing document, which is perfect for this use case:

*[_type == "article" && _id == "current-article-id"]{
  title,
  author->{name, bio},
  "otherAuthors": *[_type == "author" && _id != ^.author._ref]{
    name,
    bio
  }
}

In your application code:

// Pass the author ID as a parameter
const otherAuthors = await client.fetch(
  `*[_type == "author" && _id != $authorId]`,
  { authorId: currentArticle.author._ref }
)

Complete example for an article page:

*[_type == "article" && slug.current == $slug][0]{
  title,
  body,
  author->{
    _id,
    name,
    bio,
    image
  },
  "otherAuthors": *[_type == "author" && _id != ^.author._ref]{
    _id,
    name,
    bio,
    image
  }
}

The key concepts here:

  1. != operator - The "not equal" operator filters out matching values
  2. ^ operator - References the enclosing/parent document in nested queries
  3. .\_ref - When comparing references, use the _ref property which contains the referenced document's _id

This pattern works whether the author field is a direct reference or part of a more complex structure. Just adjust the path to match your schema (e.g., ^.author._ref vs ^.authors[0]._ref for array references).

Show original thread
13 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?