4

Is there some way to easily offset an EntityFieldQuery when using pager(), i.e. skip the first 3 nodes? range(3, NULL) doesn't work as the second value must be set, and range() also doesn't work when also using pager() which is a requirement.

Is there a substitute for something similar to this:

$query
  ->range(3, NULL) // <- Wishful thinking..
  ->pager(10)
;

Thanks,

  • Without further detail it's tough to tell what you're trying to do. I would start by looking at drupal.stackexchange.com/questions/40843/… and see if it answers your question. – Lester Peabody Jun 14 '14 at 4:55
  • @LesterPeabody Not really, but thanks. I have no issues with EFQ in general, it's just that I'm looking for a way to skip x number of nodes from the start (no matter the sort order), just like range(3, 10) skips the first 3, I would like a query with a pager that skips the first 3 (without max limit). – enzipher Jun 14 '14 at 5:11
2

First question, you've asked if you can offset the results, without having to set the limit for the total results. Logically it would make sense to be able to set $limit = FALSE, to return all results. But I believe range($offset, $limit) requires you to enter both the offset and limit. A workaround is to enter range(3,9999999999);.

Second question, you've mentioned that the -range() is not working when -pager() is set. It's a known limitation. I would assume you can run a separate query to create a pager, but that would require additional SQL requests.

  • 1
    Thanks for the reply. You are of course correct. I mainly posted this in case I had overlooked something. Seems your workaround is the only solution though, although, in the end I believe I used multiple queries. – enzipher Dec 29 '14 at 7:16
  • You're right. One query loads the items and another query counts the total items to initialize the pager. – timofey.com Dec 29 '14 at 22:51

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.