Query by Type

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

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
//To retrieve the API object check how to query the API
api.query(
    Prismic.Predicates.at('document.type', 'blog-post'),
    { orderings : '[my.blog-post.date desc]' }
).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 of the custom type “video-game” sorted alphabetically, limited to 10 games per page, showing the second page of results.

Copy
//To retrieve the API object check how to query the API
api.query(
    Prismic.Predicates.at('document.type', 'video-game'),
    { pageSize : 10, page : 2, orderings : '[my.video-game.title]' }
).then(function(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".

Copy
api.query(
  Prismic.Predicates.any("document.type", ["article", "blog_post"])
).then(function(response) {
  // response is the response object, response.results holds the documents
});