7.x entity.inc EntityFieldQuery::range($start = NULL, $length = NULL)

Restricts a query to a given range in the result set.


$start: The first entity from the result set to return. If NULL, removes any range directives that are set.

$length: The number of entities to return from the result set.

Return value

EntityFieldQuery The called object.

1 call to EntityFieldQuery::range()
EntityFieldQuery::initializePager in includes/entity.inc
Gets the total number of results and initializes a pager for the query.


includes/entity.inc, line 1023


Retrieves entities matching a given set of conditions.


public function range($start = NULL, $length = NULL) {
  $this->range = array(
    'start' => $start,
    'length' => $length,
  return $this;


artziggy’s picture

Like an array $start = 0 returns the first item.

michaellenahan’s picture

To return the first item, you supply $start = 0, $length = 1.
Like this, for example.

      $query = new EntityFieldQuery();
        ->entityCondition('entity_type', 'commerce_product')
        ->propertyOrderBy('product_id', 'DESC')
        ->range(0, 1);
timofey’s picture

Range is ignored when ->pager(5) is used. Does anyone know of a workaround?

Sociality’s picture

Is there a default value or range or if not set the Query will bring back all the entities?