Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to fetch blogPosts filtered on category in Sanity.io.

3 replies
Last updated: Feb 6, 2024
How do I fetch all
blogPosts
filtered on
category
? (
categories
is an array of references to
blogPostCategory
)
I have tried:

"blogPosts": *[_type == "blogPost" && categories[]->slug.current == "news"] { ... }
and:

"blogPosts": *[_type == "blogPost" && (categories[]->slug.current)[@ in ["news"]]] { ... }

πŸ™
Feb 6, 2024, 2:03 PM
"blogPosts": *[_type == "blogPost" && "news" in categories[]->slug.current] { ... }
does that work?
Feb 6, 2024, 2:16 PM
Yes!! Oh man was it just a js syntax misstake πŸ˜… Thanks alot
Feb 6, 2024, 2:19 PM
✨
Feb 6, 2024, 2:20 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?