Filter Sanity products by field values (checkbox/array) not documents
Good news! You absolutely can filter and group by field values (not just documents) in Sanity Studio's Structure Tool. Let me give you concrete examples for your specific use cases.
Filtering by Field Values
You can use GROQ filters directly on field values like checkboxes, strings, arrays, etc. Here's how to handle your scenarios:
1. Filter by Checkbox (Currently Available)
import {structureTool} from 'sanity/structure'
export default defineConfig({
plugins: [
structureTool({
structure: (S) =>
S.list()
.title('Products')
.items([
S.documentList()
.title('Available Products')
.filter('_type == "product" && isAvailable == true'),
S.documentList()
.title('Unavailable Products')
.filter('_type == "product" && isAvailable == false'),
S.divider(),
S.documentTypeListItem('product').title('All Products')
])
})
]
})2. Filter by Array of Strings (Week Availability)
For filtering products available in a specific week:
S.documentList()
.title('Products Available This Week')
.filter('_type == "product" && $week in availableWeeks')
.params({week: '19 July 2021 - 25 July 2021'})Or create a dynamic list with multiple week options:
const weeks = [
'19 July 2021 - 25 July 2021',
'26 July 2021 - 1 August 2021',
'2 August 2021 - 8 August 2021'
]
S.list()
.title('Products by Week')
.items([
...weeks.map(week =>
S.documentList()
.title(week)
.filter('_type == "product" && $week in availableWeeks')
.params({week})
)
])3. Combining Multiple Field Filters
You can combine multiple conditions:
S.documentList()
.title('Available Products This Week')
.filter('_type == "product" && isAvailable == true && $week in availableWeeks')
.params({week: '19 July 2021 - 25 July 2021'})Key Points
- Any field value works: You can filter by booleans, strings, numbers, arrays, dates, etc.
- GROQ operators: Use
==,!=,>,<,in,match, etc. for different comparisons - Parameters: Use
.params()to make filters dynamic and reusable - The Structure Tool customization course shows this is fully supported
The confusion might be that some examples focus on reference fields (which are documents), but the same .filter() method works for any field type in your schema. You're just writing GROQ filters that evaluate field values directly!
Show original thread4 replies
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.