Query by Type

Here you will find examples of how to query all the documents of a certain type.

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.

By One Type

Example 1

The first example shows how to query all of the documents of the custom type "blog_post" sorted by their date (from most recent to the oldest).

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

Example 2

This example shows how to query all of the documents of the custom type "video_game" sorted alphabetically, limited to 10 games per page, showing the second page of results.

Copy
this.$prismic.client.query(
  this.$prismic.Predicates.at('document.type', 'video_game'),
  { pageSize : 10, page : 2, orderings : '[my.video_game.title]' }
).then((response) => {
  // response is the response object, response.results holds the documents
});

By Multiple Types

This example shows how to query all of the documents of two different custom types ("article" and "blog_post") by using the any predicate.

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