
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, absolutely! You can fetch all articles associated with each tag in a single GROQ query. The key is to use a projection that iterates over your tags array and fetches the related articles for each tag.
Here's how you can structure your query:
*[_type == "list_component" && _id == "dsf"][0] {
tags[]{
...,
"articles": *[_type == "article" && references(^._id)]
}
}Or if you want a cleaner structure with the tag as a key:
*[_type == "list_component" && _id == "dsf"][0] {
"taggedArticles": tags[]{
"tagName": name,
"tagId": _id,
"articles": *[_type == "article" && references(^._id)]
}
}How it works:
tags[] iterates over each tag in your tags array^._id uses the parent reference operator to refer back to the tag's _id in the enclosing scope*[_type == "article" && references(^._id)] finds all articles that reference the current tag[0] after the first filter ensures you get a single object instead of an arrayIf your tags are stored as references (not inline objects), you might need to dereference them first:
*[_type == "list_component" && _id == "dsf"][0] {
"taggedArticles": tags[]-> {
"tagName": name,
"tagId": _id,
"articles": *[_type == "article" && references(^._id)]
}
}This gives you exactly what you're looking for - all tags with their associated articles in a single query! The ^ operator is the key here, allowing you to reference the parent tag's ID from within the nested query.
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