Joint session with Vercel: How to build intelligent storefronts (May 15th)

GROQ: Fetch documents by category excluding latest 8 documents

17 repliesLast updated: Nov 29, 2025

Hello,
I want to fetch some documents that contains "dance" as category. But the documents should not be one of the latest 8 documents. How can I do this in GROQ?
AI Update

You can achieve this by combining filtering, ordering, and slicing in GROQ. Here's how to fetch documents with "dance" as a category while excluding the latest 8 documents:

*[_type == "yourDocumentType" && category == "dance"] 
  | order(_createdAt desc) [8..]

Let me break this down:

The key here is the slice component syntax. Using [8..] means "start at index 8 and include everything after that." Since arrays are zero-indexed, this skips indices 0-7 (the 8 most recent documents).

If you want to also limit the total number of results, you can extend the slice:

*[_type == "yourDocumentType" && category == "dance"] 
  | order(_createdAt desc) [8..17]

This would give you documents 9-18 (skipping the latest 8, then returning the next 10).

Important note: Make sure to replace _createdAt with whatever date field makes sense for determining "latest" in your use case - it could be a custom publishedAt field or _updatedAt depending on your content model.

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