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

How to combine multiple GROQ queries in a single Sanity client call?

3 repliesLast updated: Nov 29, 2025

I have a homepage page with my Nextjs project. How can i add multiple groq queries for instance 3 blog posts, news posts both type have a name blog and news. How can I combine these 2? without having to call the sanityClient twice for each query? Thanks 🤗
AI Update

Great question! You can absolutely combine multiple GROQ queries into a single request using what's called a "projection object" syntax. This is more efficient than making separate client.fetch() calls.

Here's how to structure your query to fetch both blog posts and news posts in one request:

const query = `{
  "blogPosts": *[_type == "blog"][0...3]{
    name,
    // add other fields you need
  },
  "newsPosts": *[_type == "news"][0...3]{
    name,
    // add other fields you need
  }
}`;

const data = await sanityClient.fetch(query);
// Now you have: data.blogPosts and data.newsPosts

Important notes:

The result will be a single object with both datasets:

{
  blogPosts: [...], // your 3 blog posts
  newsPosts: [...]  // your 3 news posts
}

This approach works perfectly with usePreview() as well, since you're passing a single query string. Much more efficient than multiple fetches! 🤗

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