
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou're running into the classic GROQ challenge of checking if any element in one array matches any element in another array! The error No function in() defined for arguments (array, array) happens because the in operator can't directly compare two arrays.
The solution is to use the count() + @ pattern to check for array overlap. Here's how to fix your query:
*[_type == 'articleList'][0] {
"articlesToShow": *[
_type == 'article'
&& count(tags[]._ref[@ in ^.articleTags[]._ref]) > 0
]
}How this works:
tags[]._ref projects your article's tag references into a simple array like ["tag1", "tag2"][@ in ^.articleTags[]._ref] filters this array to only elements that exist in the parent's articleTagscount(...) counts how many matches there are> 0 means "at least one tag matches"The ^ operator accesses the parent scope (your articleList document) from within the subquery.
Alternative approach if you want it more explicit:
*[_type == 'articleList'][0] {
articleTags,
"articlesToShow": *[
_type == 'article'
&& count(tags[@._ref in ^.^.articleTags[]._ref]) > 0
]
}Note the double ^.^. - this is because tags[query] creates its own closure, so you need to go up two levels to reach the articleList document.
This pattern is one of the trickier parts of GROQ, but it's super powerful once you get the hang of it! The community thread I found shows several examples of this technique in action, including a detailed breakdown for matching related posts by tags.
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