Build with Sanity MCP in Replit. Prizes up for grabs! Submit by June 14

GROQ query: Include author reference fields across multiple content types

4 repliesLast updated: Nov 29, 2025

I have a GROQ query where I am checking for multiple types. But the author name is not working. I have author reference which I am using for all these types. How can i Include the following to this query:
Need this:

author -> {
      name,
      image
 }
inside this:

groq`*[_type in ["homePage", "page", "article", "case"] && defined(slug.current)][].slug.current`
AI Update

You need to add a projection to your query that includes the author reference. Here's how to modify your query:

*[_type in ["homePage", "page", "article", "case"] && defined(slug.current)]{
  "slug": slug.current,
  author->{
    name,
    image
  }
}

The key changes:

If you want to keep the flat array of just slug strings AND get author data, you'd need to decide on your data structure. Most likely you want something like:

*[_type in ["homePage", "page", "article", "case"] && defined(slug.current)]{
  slug,
  author->{
    name,
    image
  }
}

This returns an array of objects, each containing the full slug object and the dereferenced author data. The -> operator is what makes reference dereferencing work in GROQ projections - it follows the reference and lets you select specific fields from the referenced document.

Show original thread
4 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