
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGreat question about implementing tags and taxonomy for your blog! There are a couple of common approaches for making blog posts searchable and filterable by tags in Sanity:
The simplest approach is to use an array of strings directly in your blog post schema:
{
name: 'post',
type: 'document',
title: 'Blog Post',
fields: [
{
name: 'title',
type: 'string',
title: 'Title'
},
{
name: 'tags',
type: 'array',
title: 'Tags',
of: [{type: 'string'}],
options: {
layout: 'tags'
}
}
// other fields...
]
}This gives you a nice tag input interface in the Studio. To filter by tags in GROQ:
*[_type == "post" && "javascript" in tags]For more sophisticated taxonomy where you want to manage tags/categories as their own documents (with descriptions, slugs, etc.), use reference fields:
// Tag document type
{
name: 'tag',
type: 'document',
title: 'Tag',
fields: [
{name: 'title', type: 'string'},
{name: 'slug', type: 'slug'},
{name: 'description', type: 'text'}
]
}
// Blog post with tag references
{
name: 'post',
type: 'document',
title: 'Blog Post',
fields: [
{
name: 'tags',
type: 'array',
title: 'Tags',
of: [{
type: 'reference',
to: [{type: 'tag'}]
}]
}
]
}Then query with the -> operator to follow references:
*[_type == "post" && references(*[_type == "tag" && slug.current == "javascript"]._id)]
{
title,
tags[]->
}The reference approach is powerful because:
Once you've structured your tags, you can use GROQ to filter content. For example, to get all posts tagged with specific categories:
*[_type == "post" && count((tags[]->slug.current)[@ in ["javascript", "react"]]) > 0]Both approaches support the searchable/filterable functionality you're looking for - the choice depends on whether you need simple tagging or a more robust taxonomy system!
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