๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

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?