$pages

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?       Only hookable?    

Retrieval

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

Manipulation

Advanced

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

Cache

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

Helpers

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

For hooks

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

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