Query by Type in Javascript

Here you will find examples of how to query all the documents of a certain 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 retreive 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(blogPosts) {
    // blogPosts is the response object, blogPosts.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 retreive 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(games) {
    // games is the response object, games.results holds the documents
});