Last active
December 27, 2015 12:09
-
-
Save ocorreiododiogo/7323564 to your computer and use it in GitHub Desktop.
Loop pages in ProcessWire without building a $pageArray. This is useful for when a find() would return too many results to keep in memory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$selector = "template=pages_template"; // as an example | |
while (1) { | |
$p = wire('pages')->get("{$selector}, id>$id"); // get page with id bigger than previous | |
if(!$id = $p->id) break; // assign current page's id to $id or break the loop if it doesn't exist | |
// do stuff using $p as the current page | |
wire('pages')->uncacheAll(); // clean the memory (with $p->uncache() doesn't work. why?) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The initial
$id
is missing here.