Is it possible to fetch more than one "_type" using GROQ?

4 replies
Last updated: Nov 29, 2025
Hey - been stuck with my head in the sanity/next.js documentation for quite som time now and can't seem to find the answer that i'm looking for... But does anyone of you guys know, if it's possible to fetch more than one "_type" using GROQ? Let's say that i have a schema for my "frontpage" and my "blog-post" and i want to display them on the same page? This seems so easy with Graphql but i'm really struggling to wrap my head around how i'm supposed to do it in GROQ?
Thanks in advance
🙂
AI Update

Yes, absolutely! You can fetch multiple document types in GROQ using the in operator. It's actually quite straightforward once you see the syntax.

Here's the basic approach:

*[_type in ["frontpage", "blogPost"]]

This will fetch all documents that are either of type "frontpage" or "blogPost".

However, there's an important gotcha to be aware of: if your different document types have fields with the same name but different structures, you might get unexpected results. To handle this properly, you can use conditional projections to specify which fields to return for each type:

*[_type in ["frontpage", "blogPost"]]{
  _type == "frontpage" => {
    // Your field selection for the frontpage type
    title,
    heroImage,
    content
  },
  _type == "blogPost" => {
    // Your field selection for the blogPost type
    title,
    author,
    publishedAt,
    excerpt
  }
}

This way, you're explicitly telling GROQ which fields to return based on the document type, avoiding any conflicts or weird results.

You can also mix in common fields and ordering:

*[_type in ["frontpage", "blogPost"]] | order(_createdAt desc) {
  _type,
  _id,
  _type == "frontpage" => {
    // frontpage-specific fields
  },
  _type == "blogPost" => {
    // blogPost-specific fields
  }
}

For more details on GROQ querying, check out the Query Cheat Sheet and How Queries Work in the Sanity docs.

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