$pages API variable / Pages class

Enables loading and manipulation of Page objects, to and from the database.

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

Show $var?             Show args?        

Retrieval

NameReturnSummary 
$pages->count()
intCount and return how many pages will match the given selector. 
$pages->find($selector)
PageArray arrayGiven a Selector string, return the Page objects that match in a PageArray.
$pages->findIDs($selector)
arrayLike find() except returns array of IDs rather than Page objects 
$pages->findJoin($selector, $joinFields)
PageArrayFind pages and specify which fields to join (overriding configured autojoin settings) 
$pages->findMany($selector)
PageArrayLike find(), but with “lazy loading” to support giant result sets without running out of memory. 
$pages->findOne($selector)
Page NullPageLike find() but returns only the first match as a Page object (not PageArray). 
$pages->findRaw($selector)
arrayFind pages and return raw data from them in a PHP array 
$pages->get($selector)
Page NullPageReturns the first page matching the given selector with no exclusions 
$pages->getByIDs($ids)
PageArray PageGiven array or CSV string of Page IDs, return a PageArray 
$pages->getID($selector)
int string arrayGet one ID of page matching given selector with no exclusions, like get() but returns ID rather than a Page 
$pages->getInfoByPath(string $path)
arrayGet verbose array of info about a given page path 
$pages->has($selector)
array intIs there any page that matches the given $selector in the system? (with no exclusions) 

Advanced

NameReturnSummary 
$pages->findRaw($selector)
arrayFind pages and return raw data from them in a PHP array 
$pages->getByPath(string $path)
Page intGet a page by its path, similar to $pages->get('/path/to/page/') but with more options 
$pages->getFresh($selectorOrPage)
Page NullPageGet a fresh, non-cached copy of a Page from the database 
$pages->getPath($id)
stringGiven an ID, return a path to a page, without loading the actual page 
$pages->getRaw($selector)
arrayGet single page and return raw data in an associative array 
$pages->insertAfter(Page $page, Page $afterPage)
(nothing)Sort/move one page after another (for manually sorted pages)
$pages->insertBefore(Page $page, Page $beforePage)
(nothing)Sort/move one page above another (for manually sorted pages)
$pages->of()
boolGet or set the current output formatting state 
$pages->sort(Page $page)
intSet the “sort” value for given $page while adjusting siblings, or re-build sort for its children

Cache

NameReturnSummary 
$pages->getCache()
Page array nullGiven a Page ID, return it if it's cached, or NULL of it's not. 
$pages->uncache()
intRemove the given page(s) from the cache, or uncache all by omitting $page argument 
$pages->uncacheAll()
intRemove all pages from the cache (to clear memory) 

Helpers

NameReturnSummary 
$pages->names()
PagesNamesGet Pages API methods specific to generating and modifying page names 
$pages->pathFinder()
PagesPathFinderGet the PagesPathFinder instance 
$pages->raw()
PagesRawGet the PagesRaw instance 
$pages->request()
PagesRequestGet the PagesRequest instance 

For hooks

These methods are only useful for hooking and should not be called directly.

NameReturnSummary 
$pages->added(Page $page)
(nothing)Hook called after a new page has been added
$pages->cloneReady(Page $page, Page $copy)
(nothing)Hook called when a page is about to be cloned, but before data has been touched
$pages->cloned(Page $page, Page $copy)
(nothing)Hook called when a page has been cloned
$pages->deleteBranchReady(Page $page, array $options)
(nothing)Hook called before a branch of pages is about to be deleted, called on root page of branch only
$pages->deleteReady(Page $page)
(nothing)Hook called when a page is about to be deleted, but before data has been touched
$pages->deleted(Page $page)
(nothing)Hook called after a page and its data have been deleted
$pages->deletedBranch(Page $page, array $options, int $numDeleted)
(nothing)Hook called after a a branch of pages has been deleted, called on root page of branch only
$pages->found(PageArray $pages, array $details)
(nothing)Hook called at the end of a $pages->find(), includes extra info not seen in the resulting PageArray
$pages->moved(Page $page)
(nothing)Hook called when a page has been moved from one parent to another
$pages->publishReady(Page $page)
(nothing)Hook called right before an unpublished page is published and saved
$pages->published(Page $page)
(nothing)Hook called after an unpublished page has just been published
$pages->renamed(Page $page)
(nothing)Hook called when a page has been renamed (i.e. had its name field change)
$pages->restored(Page $page)
(nothing)Hook called when a page has been moved OUT of the trash (restored)
$pages->saveFieldReady(Page $page, Field $field)
(nothing)Hook called when Pages::saveField is ready to execute
$pages->savePageOrFieldReady(Page $page)
(nothing)Hook called when either of Pages::save or Pages::saveField is ready to execute
$pages->saveReady(Page $page)
arrayHook called just before a page is saved
$pages->saved(Page $page)
(nothing)Hook called after a page is successfully saved
$pages->savedField(Page $page, Field $field)
(nothing)Hook called after Pages::saveField successfully executes
$pages->savedPageOrField(Page $page)
(nothing)Hook called after either of Pages::save or Pages::saveField successfully executes
$pages->sorted(Page $page)
(nothing)Hook called after a page has been sorted, or had its children re-sorted
$pages->statusChangeReady(Page $page)
(nothing)Hook called when a page's status is about to be changed and saved
$pages->statusChanged(Page $page)
(nothing)Hook called when a page status has been changed and saved
$pages->templateChanged(Page $page)
(nothing)Hook called when a page's template has been changed
$pages->trashReady(Page $page)
(nothing)Hook called when a Page is about to be trashed
$pages->trashed(Page $page)
(nothing)Hook called when a page has been moved to the trash
$pages->unpublishReady(Page $page)
(nothing)Hook called right before a published page is unpublished and saved
$pages->unpublished(Page $page)
(nothing)Hook called after published page has just been unpublished

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.200

Twitter updates

  • New TinyMCE 6.2.0 Inputfield released for ProcessWire— More
    28 October 2022
  • This week we take a look at a new rich text editor for ProcessWire, why we chose it, some highlights, screenshots, and why we think you’ll like it— More
    21 October 2022
  • This week we have ProcessWire 3.0.206 on the dev branch and a new version of the ProDevTools UserActivity module, which we'll take a closer look at in this post— More
    7 October 2022

Latest news

  • ProcessWire Weekly #447
    In the 447th issue of ProcessWire Weekly we'll share the latest core updates, introduce a new third party module called RockVideoThumbnailGrabber, and more. Read on!
    Weekly.pw / 3 December 2022
  • New rich text editor for ProcessWire
    This week we take a look at a new rich text editor for ProcessWire, why we chose it, some highlights, screenshots, and why we think you’ll like it.
    Blog / 21 October 2022
  • 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