Do you need more control of your document tags and tag management? If so, we suggest setting up a custom tagging system.

Note: This will not expand the capabilities of Prismic's default tagging system. This will be an entirely different system that is completely separate.

Note: this example isn't suitable for GraphQL projects. Because the schema doesn't allow a filtering parameter to query Content Relationship fields inside Group fields.
This will only work if you're using REST or GraphQL in Gatsby.

1. Create a "Tag" Custom Type

The first step is to create a "Tag" Custom Type which consists of at least a Text field for the name of the tag.

2. Create all the tags that need

 You will have complete control of your tags. Add all the tags that you need for your project. Doing it this way, you will be able to add more or modify any tag at any point.

3. Add a Content Relationship to your documents

In your documents you want to be able to tag, add a Content Relationship field configured for your "Tag" Custom Type. This will allow your content authors to select any of your tags. If you put this field in a Group field, they will be able to select as many as they need.

4. Query all the tags in your system

In order to query all the tags in your system, you just need to query by the "Tag" Custom Type. Here are the developer docs for Javascript that show how to query all the documents of a given type.

5. Query all the documents linked to any given tag

You will also be able to query any documents linked to a certain tag in your system. To do this, you must query by the Content Relationship field that you setup.

Here are the developer docs for Javascript that show how to query by a Content Relationship field.

Did this answer your question?