---
title: "Query"
description: "Query"
url: "https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/php/reference/query"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2026-06-14"
---

# Query

## 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.

```
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();
```

Array formatted query

## addParam

To add query parameter in query

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->addParam('include_count', 'true')->find();
```

Name of key in string

Value of the key in string

## 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.

```
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();
```

Array of reference field uids

## regex

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

```
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();
```

The key to be constrained.

The regular expression pattern to match.

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

## language

To set the language code in the query

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->language('en-us')->find();
```

Language code to get entries form stack

## tags

Include tags with which to search entries.

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->tags(array('tag1', 'tag2'))->find();
```

Array of tags you want to match in the entries

## limit

A limit on the number of objects to return.

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->limit(20)->find();
```

No of objects to limit.

## skip

The number of objects to skip before returning any.

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->skip(20)->find();
```

No of objects to skip.

## ascending

Sort the results in ascending order with the given key.

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->ascending('name')->find();
```

The key to order by.

## descending

Sort the results in descending order with the given key.

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->descending('name')->find();
```

The key to order by.

## logicalOR

Combines all the queries together using OR operator

```
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();
```

Array of Query instances on which OR query executes.

## logicalAND

Combines all the queries together using AND operator

```
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()->logicalAND(array($query1, $query2))->find();
```

Array of Query instances on which AND query executes.

## except

Specifies list of field uids that would be 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();
```

Level for field uid

Field uid which get excluded from the response.

## exists

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

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->exists('age')->find();
```

Field uid against the value not existence is checked

## notExists

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

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notExists('age')->find();
```

Field uid against the value not existence is checked

## where

Query the field which has exact value as specified

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->where('age', '20')->find();
```

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

Value against which comparision is going to happen

## notEqualTo

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

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notEqualTo('age', '20')->find();
```

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

Value against which comparision is going to happen

## containedIn

Query the field value from the given set of values

```
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();
```

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

Array value against which comparison is going to happen

## notContainedIn

Query the field value other than the given set of values

```
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();
```

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

Array value against which comparison is going to happen

## lessThan

Query the field which has less value than specified one

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->lessThan('age', 20)->find();
```

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

Value against which comparison is going to happen

## lessThanEqualTo

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

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->lessThanEqualTo('age', 20)->find();
```

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

Value against which comparison is going to happen

## greaterThan

Query the field which has greater value than specified one

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->greaterThan('age', 20)->find();
```

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

Value against which comparison is going to happen

## greaterThanEqualTo

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

```
use Contentstack\Contentstack;

$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->greaterThanEqualTo('age', 20)->find();
```

Field in the entry against which comparision needs to be done

Value against which comparision is going to happen

## 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();
```

## Query | PHP Delivery SDK | Contentstack

Query builds and runs content queries in the PHP Delivery SDK, letting you filter, sort, and fetch entries from a Contentstack content type.