Query by a Field

There are a number of fields that you can query content by. Here are examples of how to query by the Number, Key Text, Document Link, and Select fields.

Before reading

This page assumes that you're using the Vue.js starter project or that you have setup your project as explained on the Integrating with existing project page.

Number Field

This example shows how to query all the "product" documents whose "price" field (Number field) is less than 100 by using the lt predicate.

Copy
this.$prismic.client.query(
  this.$prismic.Predicates.lt('my.product.price', 100)
).then((response) => {
  // response is the response object, response.results holds the documents
});

You can find more query predicates for Number fields on the Query Predicate Reference page.

Key Text Field

This queries all the "employee" custom type documents with the "job_title" field (Key Text) equal to either "Developer" or "Designer" by using the any predicate.

Copy
this.$prismic.client.query(
  this.$prismic.Predicates.any('my.employee.job_title', ['Developer', 'Designer'])
).then((response) => {
  // response is the response object, response.results holds the documents
});

To query by a particular Content Relationship (AKA a Document Link field) value, you must use the ID of the document you are looking for.

The following example queries all the "blog_post" custom type documents with the "category_link" field (a Content Relationship/Document Link field) equal to the category with a document ID of "WNje3SUAAEGBu8bc".

Copy
this.$prismic.client.query([
  this.$prismic.Predicates.at('document.type', 'blog_post'),
  this.$prismic.Predicates.at('my.blog_post.category_link', 'WNje3SUAAEGBu8bc')
]).then((response) => {
  // response is the response object, response.results holds the documents
});

Select Field

The following example shows a query for all the "book" custom type documents with the "author" field (Select field) equal to "John Doe". It also sorts the results by their title.

Copy
this.$prismic.client.query(
  this.$prismic.Predicates.at('my.book.author', 'John Doe'),
  { orderings : '[my.book.title]' }
).then((response) => {
  // response is the response object, response.results holds the documents
});

A Field inside of a Group

It is also possible to query by a field inside of a group. The following queries all the "book" custom type documents with the "name" field (Select field) equal to "John Doe". In this case the "name" field is in a group field named "author_info".

Copy
this.$prismic.client.query(
  this.$prismic.Predicates.at('my.book.author_info.name', 'John Doe'),
  { orderings : '[my.book.title]' }
).then((response) => {
  // response is the response object, response.results holds the documents
});