Sanity Pioneers: Get early access to betas, extra AI credits, and a direct line to the engineering team. Apply now

Query all authors except current article's author

13 repliesLast updated: Nov 29, 2025

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:

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

Was this answer helpful?

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.

Related contributions