$pages->findMany() method

Like find(), but with “lazy loading” to support giant result sets without running out of memory.

When using this method, you can retrieve tens of thousands, or hundreds of thousands of pages or more, without needing a pagination "limit" in your selector. Individual pages are loaded and unloaded in chunks as you iterate them, making it possible to iterate all pages without running out of memory. This is useful for performing some kind of calculation on all pages or other tasks like that. Note however that if you are building something from the result set that consumes more memory for each page iterated (like concatening a string of page titles or something), then you could still run out of memory there.

The example below demonstrates use of this method. Note that attempting to do the same using the regular $pages->find() would run out of memory, as it's unlikely the server would have enough memory to store 20k pages in memory at once.

Available since version 3.0.19.

Example

// Calculating a total from 20000 pages
$totalCost = 0;
$items = $pages->findMany("template=foo"); // 20000 pages
foreach($items as $item) {
  $totalCost += $item->cost;
}
echo "Total cost is: $totalCost";

Usage

// basic usage
$items = $pages->findMany($selector);

// usage with all arguments
$items = $pages->findMany($selector, array $options = []);

Arguments

NameType(s)Description
selectorstring, array, Selectors

Selector to find pages

options (optional)array

Options to modify behavior. See Pages::find() $options argument for details.

Return value

See Also


$pages methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #520
    In the 520th issue of ProcessWire Weekly we'll check out some of the latest additions to the ProcessWire module's directory, share some highlights from the latest weekly update from Ryan, and more. Read on!
    Weekly.pw / 27 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer