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.

Common / Retrieval / Manipulation / Advanced / For hooks

Common

Name Return Summary  
$pages->sorted(Page $page) (nothing) Hook called after a page has been sorted, or had its children re-sorted

Retrieval

Name Return Summary  
$pages->count() int Count and return how many pages will match the given selector.
$pages->find($selector) PageArray or array Given a Selector string, return the Page objects that match in a PageArray.
$pages->findIDs($selector) array Like $pages->find() except returns array of IDs rather than Page objects.
$pages->findMany($selector) PageArray Like find(), but with “lazy loading” to support giant result sets without running out of memory.
$pages->findOne($selector) Page or NullPage Like find() but returns only the first match as a Page object (not PageArray).
$pages->get($selector) Page or NullPage Returns the first page matching the given selector with no exclusions

Manipulation

Name Return Summary  
$pages->add($template, $parent) Page Add a new page using the given template and parent
$pages->clone(Page $page) Page or NullPage Clone entire page return it.
$pages->delete(Page $page) bool or int Permanently delete a page, its fields and assets.
$pages->emptyTrash() int Delete all pages in the trash
$pages->restore(Page $page) bool Restore a page in the trash back to its original location and state
$pages->save(Page $page) bool Save a page object and its fields to database.
$pages->saveField(Page $page, $field) bool Save only a field from the given page
$pages->touch($pages) bool Update page modification time to now (or the given modification time)
$pages->trash(Page $page) bool Move a page to the trash

Advanced

Name Return Summary  
$pages->getById($_ids) PageArray or Page Given an array or CSV string of Page IDs, return a PageArray
$pages->getByPath(string $path) Page or int Get a page by its path, similar to $pages->get('/path/to/page/') but with more options
$pages->getPath($id) string Given an ID, return a path to a page, without loading the actual page
$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() bool Get or set the current output formatting state
$pages->sort(Page $page) int Set the “sort” value for given $page while adjusting siblings, or re-build sort for its children
$pages->uncacheAll() int Remove all pages from the cache (to clear memory)

For hooks

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

Name Return Summary  
$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->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->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) array Hook 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->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->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: