
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, 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.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store