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

GROQ query to filter blog posts by category slug

18 repliesLast updated: Nov 29, 2025

Hello everyone! How are you?I'm still stuck with the same problem.

actually I want to make a GROQ query that selects all my blog post with a category with the slug "content-marketing".

I search this problem in google and find a solution at StackOverflow, but it doesn't work for me.

How can i do that?
AI Update

Hey there! I can help you with that. To filter blog posts by a category with a specific slug, you need to use the reference access operator (->) in your GROQ query to dereference the category reference and access its slug field.

Here's the query you need:

*[_type == "post" && category->slug.current == "content-marketing"]

Let me break this down:

If you want to include the full category data in your results, you can add a projection:

*[_type == "post" && category->slug.current == "content-marketing"] {
  _id,
  title,
  category->,
  // other fields you need
}

Common issues to watch out for:

You can test this query in Sanity Vision (the Vision plugin in your Studio) to make sure it returns the right results before using it in your code.

Let me know if you're still having issues and I can help you troubleshoot further!

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