Querying for all authors and excluding the author of the current article in Sanity.io
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:
!=operator - The "not equal" operator filters out matching values^operator - References the enclosing/parent document in nested queries.\_ref- When comparing references, use the_refproperty 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).
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.