Skip to content

Instantly share code, notes, and snippets.

@ocorreiododiogo
Last active December 27, 2015 12:09
Show Gist options
  • Save ocorreiododiogo/7323564 to your computer and use it in GitHub Desktop.
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.
$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?)
};
@LostKobrakai
Copy link

The initial $id is missing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment