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've already imported the Prismic library and retrieved the api object. If you want to learn how to do this, then refer to the How to Query the API 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
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
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") by using the any predicate.

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