I have this code that uses an EntityFieldQuery object:

$query = new EntityFieldQuery;
  ->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'yacht')
  ->propertyCondition("status", 1)
  ->pager(3, 1);

// […] switch case defaulting to:
$query->fieldOrderBy("field_bautyp", 'value', "asc");
// […]

$nodes = node_load_multiple(array_keys($result['node']));
return theme('yacht_display', array('nodes' => $nodes));

And in the yacht_display.tpl.php

<some HTML-Code and iteration over the $nodes>
<?php var_dump(theme_pager()); # => NULL ?> 

It apparently works; when I add ?page=2,5 to the URL I get different results.
Now I need to render the pager. Simply calling theme_pager() does not work; calling theme('pager', array("element" => 1)) always returns NULL.

What am I doing wrong?

UPDATE: updated the code to its current state


The ->initializePager() part is wrong; why would you do that? Kill that line, and call execute() as usual. Just calling theme('pager') should be enough; I am not sure why it fails. (Maybe because of the call to initializePager().)

  • That is true; EntityFieldQuery::execute() already invokes EntityFieldQuery::initializePager(). execute() should always be executed on query objects.
    – apaderno
    Apr 1 '11 at 17:40
  • in fact i do call EntityFieldQuery::execute() later. I added some code to my example. And it's still not working, even when I remove initializePager() :( Apr 4 '11 at 11:00
  • 1
    The problem might be that another PagerQuery is run between yours and when you call theme('pager'), it only works if it is called directly after the query is executed. You can call it in your page callback and then pass it to the template.
    – Berdir
    Apr 8 '11 at 11:52
  • dunno what was wrong with me or the code. But removed initializePager() again and simply called theme('pager')… it now works. Apr 12 '11 at 9:23

Change here: ->pager(3, 1) to ->pager(3). It will work.

  • 1
    please elaborate your answer Sep 10 '14 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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