Query by Tag

This page gives you a couple of examples of how to query documents by their tags. If you want to query all of the documents with a certain tag, then you just need to specify the document.tags.

Example 1

Here is an example of a query of all the documents with the tag “English”.

Copy
//To retrieve the API object check how to query the API
api.query(
    Prismic.Predicates.at("document.tags", ['English'])
).then(function(response) {
    // response is the response object, response.results holds the documents
});

Example 2

This example shows how to query all of the documents with either the tag “Tag 1” or “Tag 2”.

Copy
//To retrieve the API object check how to query the API
api.query(
    Prismic.Predicates.any('document.tags', ['Tag 1', 'Tag 2'])
).then(function(response) {
    // response is the response object, response.results holds the documents
});

How to get a list of all tags in your repository

When you query the api endpoint of your repository, you can receive many different properties from the repository such as the ref, Custom Types, languages, tags, etc.

To receive all the the tags from the API data, simply query the API as shown here.

Copy
import Prismic = from 'prismic-javascript';
const apiEndpoint = 'http://your-repo-name.prismic.io/api/v2';

const queryTags = async () => {
  const prismicApi = await Prismic.api(apiEndpoint);
  const tags = prismicApi.tags;
  console.log(tags)
}
queryTags();