Query

View as Markdown

Query

An initializer is responsible for creating Query object.

getQuery

Get the raw/array query from the current instance of Query/Entry.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');


$_set = ['vivo', 'samsung', 'redmi 3', 'apple'];

$result = $stack->ContentType('content_type_uid')->Query()->containsIn('title', $_set)->getQuery();

addQuery

Add Query is used to add the raw/array query to filter the entries.

NameTypeDescription
query (required)array

Array formatted query

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');


$_set = ['vivo', 'samsung', 'redmi 3', 'apple'];

$query1 = $stack->ContentType('content_type_uid_1')->Query()->containsIn('title', $_set)->getQuery();


$result = $stack->ContentType('content_type_uid')->Query()->addQuery($query1)->find();

addParam

To add query parameter in query

NameTypeDescription
key (required)string

Name of key in string

value (required)string

Value of the key in string

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->addParam('include_count', 'true')->find();

includeReferenceContentTypeUID

This method includes the content type UIDs of the referenced entries returned in the response.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->includeReferenceContentTypeUID()->find();

includeContentType

To include content_type along with entries.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->includeContentType()->find();

includeCount

Retrieve count and data of objects in result.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->includeCount()->find();

includeBranch

Include branch for publish content.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->includeBranch()->find();

includeFallback

Include fallback locale publish content, if specified locale content is not publish.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->includeFallback()->find();

includeEmbeddedItems

Include Embedded Objects (Entries and Assets) along with entry/entries details.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->includeEmbeddedItems()->find();

includeReference

Add a constraint that requires a particular reference key details.

NameTypeDescription
field_uids (required)array

Array of reference field uids

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->includeReference(array('reference_uid_1', 'reference_uid_2'))->find();

regex

Add a regular expression constraint for finding string values that match the provided regular expression.

NameTypeDescription
key (required)string

The key to be constrained.

regex (required)string

The regular expression pattern to match.

modifiersstring

Any of the following supported Regular expression modifiers.

  • use i for case-insensitive matching.
  • use m for making dot match newlines.
  • use x for ignoring whitespace in regex
use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->regex('name', '^browser')->find();

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->regex('name', '^browser', 'i')->find();

language

To set the language code in the query

NameTypeDescription
lang (required)string

Language code to get entries form stack

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->language('en-us')->find();

tags

Include tags with which to search entries.

NameTypeDescription
tags (required)array

Array of tags you want to match in the entries

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->tags(array('tag1', 'tag2'))->find();

limit

A limit on the number of objects to return.

NameTypeDescription
limit (required)int

No of objects to limit.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->limit(20)->find();

skip

The number of objects to skip before returning any.

NameTypeDescription
skip (required)int

No of objects to skip.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->skip(20)->find();

ascending

Sort the results in ascending order with the given key.

NameTypeDescription
field_uid (required)string

The key to order by.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->ascending('name')->find();

descending

Sort the results in descending order with the given key.

NameTypeDescription
field_uid (required)string

The key to order by.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->descending('name')->find();

logicalOR

Combines all the queries together using OR operator

NameTypeDescription
queries (required)array

Array of Query instances on which OR query executes.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');


$query1 = $stack->ContentType('content_type_uid_1')->Query()->where('title', 'Redmi Note 3');

$query2 = $stack->ContentType('content_type_uid_1')->Query()->where('color', 'Gold');


$result = $stack->ContentType('content_type_uid')->Query()->logicalOr(array($query1, $query2))->find();

logicalAND

Combines all the queries together using AND operator

NameTypeDescription
queries (required)array

Array of Query instances on which AND query executes.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');


$query1 = $stack->ContentType('content_type_uid_1')->Query()->where('title', 'Redmi Note 3');

$query2 = $stack->ContentType('

')->Query()->where('color', 'Gold');


$result = $stack->ContentType('content_type_uid')->Query()->logicalAND(array($query1, $query2))->find();

except

Specifies list of field uids that would be excluded from the response.

NameTypeDescription
level (required)string

Level for field uid

field_uid (required)array

Field uid which get excluded from the response.

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->except('BASE',array('price'))->find();

exists

Add a constraint that requires, a specified key does exists in response.

NameTypeDescription
field_uid (required)string

Field uid against the value not existence is checked

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->exists('age')->find();

notExists

Add a constraint that requires, a specified key does not exists in response.

NameTypeDescription
field_uid (required)string

Field uid against the value not existence is checked

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->notExists('age')->find();

where

Query the field which has exact value as specified

NameTypeDescription
field (required)string

Field in the entry against which comparison needs to be done.

value (required)string

Value against which comparision is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->where('age', '20')->find();

notEqualTo

Query the field which has not equal to value than specified one





NameTypeDescription
field (required)string

Field in the entry against which comparison needs to be done.

value (required)string

Value against which comparision is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->notEqualTo('age', '20')->find();

containedIn

Query the field value from the given set of values





NameTypeDescription
field (required)string

Field in the entry against which comparison needs to be done.

value (required)string

Array value against which comparison is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->containedIn("field_uid", ["Christmas Deal", "Summer Deal"])->find();

notContainedIn

Query the field value other than the given set of values





NameTypeDescription
field (required)string

Field in the entry against which comparison needs to be done.

value (required)string

Array value against which comparison is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->notContainedIn("field_uid", ["Christmas Deal", "Summer Deal"])->find();

lessThan

Query the field which has less value than specified one





NameTypeDescription
field (required)string

Field in the entry against which comparison needs to be done.

value (required)string

Value against which comparison is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->lessThan('age', 20)->find();

lessThanEqualTo

Query the field which has less or equal value than specified one





NameTypeDescription
field (required)string

Field in the entry against which comparison needs to be done.

value (required)string

Value against which comparison is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->lessThanEqualTo('age', 20)->find();

greaterThan

Query the field which has greater value than specified one



NameTypeDescription
fieldstring

Field in the entry against which comparison needs to be done.

value (required)string

Value against which comparison is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->greaterThan('age', 20)->find();

greaterThanEqualTo

Query the field which has greater or equal value than specified one.

NameTypeDescription
field (required)string

Field in the entry against which comparision needs to be done

value (required)string

Value against which comparision is going to happen

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->greaterThanEqualTo('age', 20)->find();

find

Get all entries based on the specified subquery

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->find();

count

To get only count result

use Contentstack\Contentstack;


$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

$result = $stack->ContentType('content_type_uid')->Query()->count()->find();