Query by a Field

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

Number - This queries all the products with the price field (Number) less than 100. You can read more about the specific number-based Predicates on the Number & Range field page.

Copy
      api.query(
    Prismic.Predicates.lt('my.product.price', 100)
).then(function(content) {
    // content is the response object, content.results holds the documents
});
    
Copy
      $content = $api->query(
    Predicates::lt('my.product.price', 100)
);
// $content contains the response object, $content->getResults() holds the documents
    
Copy
      content = api.query(
    Prismic::Predicates.lt("my.product.price", 100)
)
# content contains the response object, content.results holds the documents
    

Key Text - This queries all the employee custom type documents with the job-title field (Key Text) equal to either “Developer” or “Designer”

Copy
      api.query(
    Prismic.Predicates.any('my.employee.job-title', ['Developer', 'Designer'])
).then(function(content) {
    // content is the response object, content.results holds the documents
});
    
Copy
      $content = $api->query(
    Predicates::any('my.employee.job-title', ['Developer', 'Designer'])
);
// $content contains the response object, $content->getResults() holds the documents
    
Copy
      content = api.query(
    Prismic::Predicates.any("my.employee.job-title", ["Developer", "Designer"])
)
# content contains the response object, content.results holds the documents
    

Select - This queries all the “book” custom type documents with the author field (Select) equal to “John Doe”. It also sorts the results by their title.

Copy
      api.query(
    Prismic.Predicates.at('my.book.author', 'John Doe'),
    { orderings : '[my.book.title]' }
).then(function(content) {
    // content is the response object, content.results holds the documents
});
    
Copy
      $content = $api->query(
    Predicates::at('my.book.author', 'John Doe'),
    [ 'orderings' => '[my.book.title]' ]
);
// $content contains the response object, $content->getResults() holds the documents
    
Copy
      content = api.query(
    Prismic::Predicates.at("my.book.author", "John Doe"),
    { "orderings" => "[my.book.title]" }
)
# content contains the response object, content.results holds the documents
    

Select in 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) equal to “John Doe”. In this case the “name” field is in a group field named “author-info”.

Copy
      api.query(
    Prismic.Predicates.at('my.book.author-info.name', 'John Doe'),
    { orderings : '[my.book.title]' }
).then(function(content) {
    // content is the response object, content.results holds the documents
});
    
Copy
      $content = $api->query(
    Predicates::at('my.book.author-info.name', 'John Doe'),
    [ 'orderings' => '[my.book.title]' ]
);
// $content contains the response object, $content->getResults() holds the documents
    
Copy
      content = api.query(
    Prismic::Predicates.at("my.book.author-info.name", "John Doe"),
    { "orderings" => "[my.book.title]" }
)
# content contains the response object, content.results holds the documents