$pages->findRaw() method

Find pages and return raw data from them in a PHP array

Note that the data returned from this method is raw and unformatted, directly as it exists in the database. In most cases you should use $pages->find() instead, but this method provides a convenient alternative for some cases.

The $selector argument can be any page-finding selector that you would provide to a regular $pages->find() call. The most interesting stuff relates to the $field argument though, which is what the rest of this section looks at:

If you omit the $field argument, it will return all data for the found pages in an array where the keys are the page IDs and the values are associative arrays containing all of each page raw field and property values indexed by name… $a = $pages->findRaw("template=blog"); …but findRaw() is more useful for cases where you want to retrieve specific things without having to load the entire page (or its data). Below are a few examples of how you can do this.

Available since version 3.0.172.

Example

// If you provide a string (field name) for `$field`, then it will return an 
// array with the values of the `data` column of that field. The `$field` can
// also be the name of a native pages table property like `id` or `name`.
$a = $pages->findRaw("template=blog", "title");

// The above would return an array of blog page titles indexed by page ID. If
// you provide an array for `$field` then it will return an array for each page,
// where each of those arrays is indexed by the field names you requested.
$a = $pages->findRaw("template=blog", [ "title", "date" ]);

// You may specify field name(s) like `field.subfield` to retrieve a specific
// column/subfield. When it comes to Page references or Repeaters, the subfield
// can also be the name of a field that exists on the Page reference or repeater.
$a = $pages->findRaw("template=blog", [ "title", "categories.title" ]);

// You can also use this format below to get multiple subfields from one field:
$a = $pages->findRaw("template=blog", [ "title", "categories" => [ "id", "title" ] ]);

// You may specify wildcard field name(s) like `field.*` to return all columns
// for `field`. This retrieves all columns from the field’s table. This is
// especially useful with fields like Table or Combo that might have several
// different columns:
$a = $pages->findRaw("template=villa", "rates_table.*" ); 

Usage

// basic usage
$array = $pages->findRaw($selector);

// usage with all arguments
$array = $pages->findRaw($selector, $field = '', array $options = []);

Arguments

NameType(s)Description
selectorstring, array, Selectors, int

Page matching selector or page ID

field (optional)string, array, Field

Name of field/property to get, or array of them, or omit to get all (default='')

options (optional)array

Return value

array


$pages methods and properties

API reference based on ProcessWire core version 3.0.172

Twitter updates

  • This week ProcessWire gained powerful new tools for finding pages and controlling how they are loaded. If you like to maximize performance and efficiency, you’ll like what 3.0.172 brings— More
    5 February 2021
  • ProcessWire 3.0.171 dev branch core updates – More
    22 January 2021
  • Preliminary 2021 roadmap in progress in this week’s update— More
    8 January 2021

Latest news

  • ProcessWire Weekly #352
    In the 352nd issue of ProcessWire Weekly we're going to check out the latest core updates available in ProcessWire 3.0.172, introduce a neat third party module called Admin Autosize Textareas, and more. Read on!
    Weekly.pw / 6 February 2021
  • ProcessWire 3.0.172 – Find faster and more efficiently
    This week ProcessWire gained powerful new tools for finding pages and controlling how they are loaded. If you like to maximize performance and efficiency, you’ll like what 3.0.172 brings.
    Blog / 5 February 2021
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK