PageArray class

PageArray is a paginated type of WireArray that holds multiple Page objects.

Please see the WireArray and PaginatedArray types for available methods, as they are not repeated here, except where PageArray has modified or extended those types in some manner. The PageArray type is functionally identical to WireArray and PaginatedArray except that it is focused specifically on managing Page objects.

PageArray is returned by all API methods in ProcessWire that can return more than one page at once. $pages->find() and $page->children() are common examples that return PageArray.

You can create a new PageArray using any of the methods below:

// the most common way to create a new PageArray and add a $page to it
$a = new PageArray();
$a->add($page);

// ProcessWire 3.0.123+ can also create PageArray like this:
$a = PageArray(); // create blank
$a = PageArray($page); // create + add one page
$a = PageArray([ $page1, $page2, $page3 ]); // create + add pages

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the PageArray class also inherits all the methods and properties of: PaginatedArray, WireArray and Wire.

Show class?             Show args?        

Common

NameReturnSummary 
PageArray::add($item)
$thisAdd one or more Page objects to this PageArray. 
PageArray::findOnePage(string $selector)
Page NullPageSame as find() or findOne() methods, but always returns a Page (whether Page or NullPage) 
PageArray::first Page null First item 
PageArray::getPage($key)
Page NullPageLike the base get() method but can only return Page objects (whether Page or NullPage) 
PageArray::getPageByID(int $id)
NullPage PageGet Page from this PageArray having given ID, or return NullPage if not present 
PageArray::getPageByName(string $name)
NullPage PageGet Page from this PageArray having given name, or return NullPage if not present 
PageArray::getSelectors()
Selectors string nullReturn the Selectors that led to this PageArray, or null if not set/applicable. 
PageArray::last Page null Last item 

Additional methods and properties

In addition to the methods and properties above, PageArray also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #544
    In the 150th issue of ProcessWire Weekly we'll check out brand-new third party module called Inputfield Dependency Helper, share some recent highlights from the support forum, and more. Read on!
    Weekly.pw / 12 October 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani