How to use pager_default_initialize with entity field query? In order to apply pagination on nodes which get rendered into block, I am using pager_default_initialize method. Basically I have written a query, execute that query and after that write pager_default_initialize() function. But it is not applying limit to content per page. i.e. "paging" is not working.

    $query = new EntityFieldQuery();
    $query-&gt;entityCondition('entity_type', 'node')
          -&gt;entityCondition('bundle', $content_type)
          -&gt;propertyCondition('status',1);
  $results = $query-&gt;execute();
pager_default_initialize(count($results['node']), 2);


here, the count of nodes is 4 and I want to display only 2 nodes with pagination.

return theme('calender', array('calender' =&gt; $output)).theme('pager');


Here I'm using theme('pager') for pagination interface.

Pagination UI is displayed, but I'm not able to put limit "2" to the no. of count of nodes. Any suggestion where I went wrong?
If your motive is to create a pager for those results, I suggest you to use -&gt;pager() on your EntityFieldQuery.

See this question EntityFieldQuery display pager

if ($type == 21) { 
  $query = new EntityFieldQuery(); 

  $entities = $query-&gt;entityCondition('entity_type', 'node')
    -&gt;propertyCondition('type', 'product') 
    -&gt;fieldCondition('field_razred', 'tid', array (607,608,609,610), 'IN')
    -&gt;pager(10) // this is the bit you're missing
    -&gt;execute(); 

  $nodes = node_load_multiple(array_keys($entities['node'])); 
  print render(node_view_multiple($nodes, 'teaser')) . theme('pager');
}


If you necessarily want to use pager_default_initialize(), see this post Creating pager in Drupal (without db_select() and PagerDefault)

$per_page = 10;
// Initialize the pager
$current_page = pager_default_initialize(count($rows), $per_page);
// Split your list into page sized chunks
$chunks = array_chunk($rows, $per_page, TRUE);
// Show the appropriate items from the list
$output = theme('table', array('header' =&gt; $header, 'rows' =&gt; $chunks[$current_page]));
// Show the pager
$output .= theme('pager', array('quantity',count($rows)));


Hope these examples will help you.