
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your query, you're on the right track! The issue is that when you filter with tags[]-> title == "NextJS", you're checking if any tag matches, but then you need to actually project/return the title in your results.
Here are a few approaches depending on what you want to achieve:
If you want just the matching tag titles:
*[_type == "contents" && "NextJS" in tags[]->title] {
"matchingTags": tags[]->title
}If you want only the "NextJS" title specifically:
*[_type == "contents" && "NextJS" in tags[]->title] {
"nextjsTag": tags[]->{title}[title == "NextJS"][0].title
}If you want to filter the tags array to only include matching references:
*[_type == "contents" && "NextJS" in tags[]->title] {
_id,
"filteredTags": tags[]->{ title }[title == "NextJS"]
}The key things to understand here:
tags[]->title dereferences all tag references and gets their titles as an arraytags[]->{title} dereferences and projects each tag, giving you more control over filteringThe most common pattern for your use case would be:
*[_type == "contents" && "NextJS" in tags[]->title] {
...,
"tagTitles": tags[]->title
}This gives you all content documents that have a "NextJS" tag, and returns an array of all tag titles (including "NextJS") for each document. The ... spreads all other fields from the content document, while "tagTitles" creates a new field with the dereferenced tag titles.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store