0

How do I load any page other than the first page with Entity Field Query pager?

$query = new EntityFieldQuery();

$result = $query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'event')
  ->pager(4)
  ->execute();

This returns the first 4 nodes. If i have 12 nodes, how do I return page 2 nodes 4-8 or page 3 nodes 8-12.

The documentation states I can only pass $limit and $element. Have I missed something? What's the point of a pager that only loads the first page.

1 Answer 1

2

Here are some pointers:

  • The query looks fine
  • Try adding the parameter ?page=1 to your request and you should see different items. Page 0 is the one you see by default.
  • You need to display the pager object while building your output, like: $output['pager'] = array('#theme' => 'pager'); This will make the pager visible and allow users to click on back/next buttons to navigate through pages to see other items which are not on the current page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.