GROQ: Fetch documents by category excluding latest 8 documents
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:
*[_type == "yourDocumentType" && category == "dance"]- Filters documents to only those with "dance" as the category| order(_createdAt desc)- Sorts all matching documents by creation date, newest first (you could also use_updatedAtor any other date field)[8..]- Slices the array starting from index 8 to the end, effectively skipping the first 8 (latest) documents
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 thread17 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.