How to Return Blog Posts by Slug Excluding the Slug that is being Passed to the Query

2 replies
Last updated: Aug 3, 2021
Hi everyone, it's me again. πŸ˜›
I trying to return blog posts by slug excluding the slug that is being passed to the query.

I've tried the following without success:


*[_type == 'post' && slug.current match !$slug]
*[_type == 'post' && !slug.current match $slug]

Aug 3, 2021, 12:15 PM
Have you tried
*[_type == 'post' && !(slug.current match $slug)]
Aug 3, 2021, 1:39 PM
user A
Thank you, that worked. 😎 πŸŽ‰
Aug 3, 2021, 2:12 PM

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.

Was this answer helpful?