How to get the titles of tags attached to stories in Sanity.io
You're really close! The solution is to use the dereference operator -> in GROQ to resolve those references to the actual tag documents.
Here's how to modify your query:
*[_type == "story"]{
_type,
"title": author,
tags[]->
}The key is tags[]-> which does two things:
tags[]- iterates over each item in the tags array->- dereferences each reference to fetch the actual storyTag document
This will give you the full storyTag documents in your results. If you only want the titles (which sounds like what you need), you can be more specific:
*[_type == "story"]{
_type,
"title": author,
tags[]->{title}
}Or even cleaner, map it to just an array of title strings:
*[_type == "story"]{
_type,
"title": author,
"tagTitles": tags[]->title
}The reference access operator (->) internally executes a subquery to fetch the referenced document by its _id, replacing the reference object with the actual document data. When you combine it with array notation [] and projections, you can extract exactly the fields you need from those referenced documents.
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.