$page / Page

Class used by all Page objects in ProcessWire.

The $page API variable represents the current page being viewed. However, the documentation here also applies to all Page objects that you may work with in the API. We use $page as the most common example throughout the documentation, but you can substitute that with any variable name representing a Page.


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

Show $var?     Show args?       Only hookable?    

Common

NameReturnSummary 
child()
Page NullPageReturn the page’s first single child that matches the given selector.
Can also be used as property: child
 
children()
PageArray arrayReturn this page’s children, optionally filtered by a selector
Can also be used as property: children
 
find()
PageArrayFind descendant pages matching given selector 
findOne()
Page NullPageFind one descendant page matching given selector 
get(string $key)
mixedGet the value of a Page property (see details for several options) 
getIcon()
stringGet the icon name associated with this Page (if applicable)
getMultiple($keys)
arrayGet multiple Page property/field values in an array 
hasChildren()
intReturn the number of visible children, optionally with conditions
Can also be used as property: hasChildren
 
hasFile(string $file)
bool stringDoes Page have given filename in its files directory? 
hasStatus($status)
boolDoes this page have the given status? 
httpUrl()
stringReturns the URL to the page, including scheme and hostname
Can also be used as property: httpUrl
 
id int The numbered ID of the current page  
if($key)
mixed string boolIf value is available for $key return or call $yes condition (with optional $no condition)
name string The name assigned to the page, as it appears in the URL  
numChildren()
intReturn number of all children, optionally with conditions
Can also be used as property: numChildren
 
numParents()
intReturn number of parents (depth relative to homepage) that this page has, optionally filtered by a selector
Can also be used as property: numParents
 
of()
boolGet or set the current output formatting state of the page 
parent()
PageReturn this page’s parent Page, or–if given a selector–the closest matching parent.
Can also be used as property: parent
 
parents()
PageArrayReturn this page’s parent pages, or the parent pages matching the given selector.
Can also be used as property: parents
 
preload()
arrayPreload multiple fields together as a group (experimental) 
rootParent()
PageGet the lowest-level, non-homepage parent of this page
Can also be used as property: rootParent
save()
boolSave the entire page to the database, or just a field from it 
saveFields($fields)
arraySave only the given named fields for this page 
set(string $key, mixed $value)
Page WireDataSet the value of a page property 
setEditor(WirePageEditor $editor)
NoneTells the page what Process it is being edited by, or simply that it's being edited
template()
Template nullGet or set template
Can also be used as property: template
 
url()
stringReturns the URL to the page (optionally with additional $options)
Can also be used as property: url
 

Traversal

NameReturnSummary 
child()
Page NullPageReturn the page’s first single child that matches the given selector.
Can also be used as property: child
 
children()
PageArray arrayReturn this page’s children, optionally filtered by a selector
Can also be used as property: children
 
closest($selector)
Page NullPageFind the closest parent page matching your selector 
descendant()
Page NullPageFind one descendant page, alias of Page::findOne(), see that method for details. 3.0.116
descendants()
PageArrayFind descendant pages, alias of Page::find(), see that method for details. 3.0.116
find()
PageArrayFind descendant pages matching given selector 
findOne()
Page NullPageFind one descendant page matching given selector 
hasChildren()
intReturn the number of visible children, optionally with conditions
Can also be used as property: hasChildren
 
hasLinks int Number of visible pages (to current user) linking to this page in Textarea/HTML fields.  
hasReferences int Number of visible pages (to current user) referencing this page with page reference fields.  
index()
intReturn the index/position of this page relative to siblings.
Can also be used as property: index
 
links()
PageArrayReturn pages linking to this one (in Textarea/HTML fields)
Can also be used as property: links
matches($s)
boolGiven a selector, return whether or not this Page matches using runtime/memory comparison 
matchesDatabase($s)
boolGiven a selector, return whether or not this Page matches by querying the database 
next()
Page NullPageReturn the next sibling page
Can also be used as property: next
 
nextAll()
PageArray intReturn all sibling pages after this one, optionally matching a selector 
nextUntil()
PageArrayReturn all sibling pages after this one until matching the one specified 
numChildren()
intReturn number of all children, optionally with conditions
Can also be used as property: numChildren
 
numDescendants()
intReturn number of descendants (children, grandchildren, great-grandchildren, …), optionally with conditions
Can also be used as property: numDescendants
 
numLinks int Total number of pages manually linking to this page in Textarea/HTML fields.  
numReferences int Total number of pages referencing this page with Page reference fields.  
numReferencing int Total number of other pages this page is pointing to (referencing) with Page fields.  
parent()
PageReturn this page’s parent Page, or–if given a selector–the closest matching parent.
Can also be used as property: parent
 
parents()
PageArrayReturn this page’s parent pages, or the parent pages matching the given selector.
Can also be used as property: parents
 
parentsUntil()
PageArrayReturn all parents from current page till the one matched by $selector 
prev()
Page NullPageReturn the previous sibling page
Can also be used as property: prev
 
prevAll()
Page NullPage intReturn all sibling pages before this one, optionally matching a selector 
prevUntil()
PageArrayReturn all sibling pages before this one until matching the one specified 
references()
PageArray arrayReturn pages that have Page reference fields pointing to this one (references)
Can also be used as property: references
referencing PageArray Return pages that this page is referencing by way of Page reference fields.  
rootParent()
PageGet the lowest-level, non-homepage parent of this page
Can also be used as property: rootParent
siblings()
PageArrayReturn this Page’s sibling pages, optionally filtered by a selector.
Can also be used as property: siblings
 

Manipulation

NameReturnSummary 
addStatus($statusFlag)
$thisAdd the specified status to this page 
addUrl($url)
boolAdd a new URL that redirects to this page and save immediately (returns false if already taken).
delete()
bool intDelete this page from the database 
isChanged()
boolHas the Page changed since it was loaded? 
of()
boolGet or set the current output formatting state of the page 
removeStatus($statusFlag)
$thisRemove the specified status from this page 
removeUrl($url)
boolRemove a URL that redirects to this page and save immediately.
resetTrackChanges()
$thisClears out any tracked changes and turns change tracking ON or OFF 
save()
boolSave the entire page to the database, or just a field from it 
set(string $key, mixed $value)
Page WireDataSet the value of a page property 
setAndSave($key)
boolQuickly set field value(s) and save to database 
setName(string $value)
$thisSet the page name, optionally for specific language 
setQuietly(string $key, mixed $value)
$thisQuietly set the value of a page property. 
status()
int array PageGet or set current status
Can also be used as property: status
 
trash()
boolMove this page to the trash 

Date time

NameReturnSummary 
created int Unix timestamp of when the page was created.  
createdStr string Date/time when the page was created (formatted date/time string).  
modified int Unix timestamp of when the page was last modified.  
modifiedStr string Date/time when the page was last modified (formatted date/time string).  
published int Unix timestamp of when the page was published.  
publishedStr string Date/time when the page was published (formatted date/time string).  

Access

NameReturnSummary 
addable()
boolReturns true if the current user can add children to the page, false if not. Optionally specify the page to be added for additional access checking.
Can also be used as property: addable
cloneable()
boolCan current user clone this page? Specify false for $recursive argument to ignore whether children are cloneable. 3.0.239
Can also be used as property: cloneable
deletable()
boolAlias of deleteable().
Can also be used as property: deletable
deleteable()
boolReturns true if the page is deleteable by the current user, false if not.
Can also be used as property: deleteable
editable()
boolReturns true if the page (and optionally field) is editable by the current user, false if not.
Can also be used as property: editable
getAccessParent()
Page NullPageReturns the page from which role/access settings are inherited from 
getAccessRoles()
PageArrayReturn Roles (PageArray) that have access to this page 
getAccessTemplate()
Template nullReturns the template from which role/access settings are inherited from 
hasAccessRole($role)
boolReturns whether this page has the given access role 
listable()
boolReturns true if the page is listable by the current user, false if not.
Can also be used as property: listable
moveable()
boolReturns true if the current user can move this page. Optionally specify the new parent to check if the page is moveable to that parent.
Can also be used as property: moveable
publishable()
boolReturns true if the page is publishable by the current user, false if not.
Can also be used as property: publishable
restorable()
boolReturns true if page is in the trash and is capable of being restored to its original location. 3.0.107
sortable()
boolReturns true if the current user can change the sort order of the current page (within the same parent).
Can also be used as property: sortable
trashable()
boolReturns true if the page is trashable by the current user, false if not.
Can also be used as property: trashable
viewable()
boolReturns true if the page (and optionally field) is viewable by the current user, false if not.
Can also be used as property: viewable

Output rendering

NameReturnSummary 
edit()
string bool mixedGet front-end editable output for field (requires PageFrontEdit module to be installed)
of()
boolGet or set the current output formatting state of the page 
render()
string mixedReturns rendered page markup. Please see the PageRender::renderPage() method for arguments and usage details.
Can also be used as property: render
renderField(string $fieldName)
mixed stringRender given $fieldName using site/templates/fields/ markup file
renderValue(mixed $value)
mixed stringRender given $value using /site/templates/fields/ markup file

Status

NameReturnSummary 
addStatus($statusFlag)
$thisAdd the specified status to this page 
hasStatus($status)
boolDoes this page have the given status? 
is($status)
boolDoes this page have the specified status number or template name? 
isHidden()
boolDoes this page have a 'hidden' status? 
isLocked()
boolDoes this page have a 'locked' status? 
isTrash()
boolIs this Page in the trash? 
isUnpublished()
boolDoes this page have a 'unpublished' status? 
removeStatus($statusFlag)
$thisRemove the specified status from this page 
status()
int array PageGet or set current status
Can also be used as property: status
 
statusPrevious int null Previous status, if status was changed. Null if not.  

Constants

NameReturnSummary 
Page::statusHidden const1024Page is hidden and excluded from page finding methods unless overridden by selector (name: "hidden"). 
Page::statusIncomplete const128 
Page::statusLocked const4Indicates page is locked for changes (name: "locked") 
Page::statusUnpublished const2048Page is unpublished (not publicly visible) and excluded from page finding methods unless overridden (name: "unpublished"). 

Languages

Multi-language methods require these core modules: LanguageSupport, LanguageSupportFields, LanguageSupportPageNames.

NameReturnSummary 
getLanguageName()
array stringGet page name for language(s). If given a Language object, it returns a string. If given array of language names, or argument omitted, it returns an array like [ 'default' => 'hello', 'es' => 'hola' ];. 3.0.236
getLanguageStatus()
array boolGet active status for language(s). If given a $language (Language or name of language) it returns a boolean. If given multiple language names (array), or argument omitted, it returns array like [ 'default' => true, 'fr' => false ];. 3.0.236
getLanguageValue($language, $field)
mixedGet value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object. Field should be field name (string).
getLanguageValues($field)
arrayGet values for field or one or more languages (requires LanguageSupport module). $field should be field/property name (string), $langs should be array of language names, or omit for all languages. Returns array of values indexed by language name. 3.0.236
getLanguages()
PageArray nullGet languages active for this page and viewable by current user 
localHttpUrl()
stringReturn the page URL (including scheme and hostname) in the current user's language, or specify $language argument (Language object, name, or ID).
localName()
stringReturn the page name in the current user’s language, or specify $language argument (Language object, name, or ID), or TRUE to use default page name when blank (instead of 2nd argument).
localPath()
stringReturn the page path in the current user's language, or specify $language argument (Language object, name, or ID).
localUrl()
stringReturn the page URL in the current user's language, or specify $language argument (Language object, name, or ID).
setLanguageName($language)
PageSet page name for language with setLanguageName('es', 'hola'); or set multiple with setLanguageName([ 'default' => 'hello', 'es' => 'hola' ]); 3.0.236
setLanguageStatus($language)
PageSet active status for language(s), can be called as setLanguageStatus('es', true); or setLanguageStatus([ 'es' => true, 'br' => false ]); to set multiple. 3.0.236
setLanguageValue($language, $field, $value)
PageSet value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object. Field should be field name (string).
setLanguageValues($field, array $values)
PageSet value for field in one or more languages (requires LanguageSupport module). $field should be field/property name (string), $values should be array of values indexed by language name. 3.0.236

System

Most system properties directly correspond to columns in the pages database table.

NameReturnSummary 
created int Unix timestamp of when the page was created.  
created_users_id int ID of created user.  
id int The numbered ID of the current page  
modified int Unix timestamp of when the page was last modified.  
modified_users_id int ID of last modified user.  
name string The name assigned to the page, as it appears in the URL  
parent_id int The numbered ID of the parent page or 0 if homepage or not assigned.  
published int Unix timestamp of when the page was published.  
sort int Sort order of this page relative to siblings (applicable when manual sorting is used).  
sortPrevious int null Previous sort order, if changed 3.0.235+  
sortfield()
stringReturn the field name by which children are sorted
Can also be used as property: sortfield
 
templates_id int The numbered ID of the template usedby this page.  

Advanced

NameReturnSummary 
count()
intReturns number of children page has, affected by output formatting mode. 
draft()
ProDraft int string Page arrayHelper method for drafts (added by ProDrafts).
fieldgroup Fieldgroup Fieldgroup used by page template. Shorter alias for template->fieldgroup (same as fields)  
fields Fieldgroup All the Fields assigned to this page (via its template). Returns a Fieldgroup.  
getField($field)
Field nullGet a Field object in context or NULL if not valid for this page 
getFields()
FieldsArrayReturns a FieldsArray of all Field objects in the context of this Page 
getFormatted(string $key)
mixedGet the formatted value of a field, regardless of output formatting state 
getInputfield(string $fieldName)
Inputfield InputfieldWrapper nullGet a single Inputfield for the given field name 
getIterator()
ArrayObjectEnables iteration of the page's properties and fields with PHP’s foreach() 
getMarkup(string $key)
stringReturn the markup value for a given field name or {tag} string
getText(string $key)
stringSame as getMarkup() except returned value is plain text 
getUnformatted(string $key)
mixedGet the unformatted value of a field, regardless of current output formatting state 
hasField($field)
bool stringReturns whether or not given $field name, ID or object is valid for this Page 
meta()
WireDataDB string array int floatGet or set page’s persistent meta data 
outputFormatting bool Whether output formatting is enabled or not. Same as calling of() with no arguments.  
setQuietly(string $key, mixed $value)
$thisQuietly set the value of a page property. 
setUnformatted(string $key, mixed $value)
selfSet the unformatted value of a field, regardless of current output formatting state 

For hooks

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

NameReturnSummary 
$this->callUnknown(string $method, array $arguments)
null mixedIf method call resulted in no handler, this hookable method is called.
getUnknown(string $key)
null mixedHookable method called when a request to a field was made that didn't match anything
loaded()
NoneFor hooks to listen to, triggered when page is loaded and ready

Urls

NameReturnSummary 
addUrl($url)
boolAdd a new URL that redirects to this page and save immediately (returns false if already taken).
editUrl()
stringReturn the URL necessary to edit this page
Can also be used as property: editUrl
 
httpUrl()
stringReturns the URL to the page, including scheme and hostname
Can also be used as property: httpUrl
 
localHttpUrl()
stringReturn the page URL (including scheme and hostname) in the current user's language, or specify $language argument (Language object, name, or ID).
localPath()
stringReturn the page path in the current user's language, or specify $language argument (Language object, name, or ID).
localUrl()
stringReturn the page URL in the current user's language, or specify $language argument (Language object, name, or ID).
removeUrl($url)
boolRemove a URL that redirects to this page and save immediately.
url()
stringReturns the URL to the page (optionally with additional $options)
Can also be used as property: url
 
urls()
arrayReturn all URLs that this page can be accessed from (excluding URL segments and pagination)
Can also be used as property: urls
 

Files

NameReturnSummary 
filesManager()
PagefilesManagerReturn instance of PagefilesManager specific to this Page
Can also be used as property: filesManager
 
filesPath()
stringReturns the path for files, creating it if it does not yet exist
Can also be used as property: filesPath
 
filesUrl()
stringReturns the URL for files, creating it if it does not yet exist
Can also be used as property: filesUrl
 
hasFiles()
boolDoes the page have a files path and one or more files present in it?
Can also be used as property: hasFiles
 
hasFilesPath()
boolDoes the page have a files path for storing files? 
secureFiles()
bool nullDoes this Page use secure Pagefiles? 

Previous

Provides access to the previously set runtime value of some Page properties.

NameReturnSummary 
namePrevious string null Previous name, if changed. Null or blank string if not.  
parentPrevious Page null Previous parent, if parent was changed. Null if not.  
statusPrevious int null Previous status, if status was changed. Null if not.  
templatePrevious Template null Previous template, if template was changed. Null if not.  

Properties

NameReturnSummaryDefault
title string The page’s title (headline) text 

Users

NameReturnSummary 
createdUser User NullPage The user that created this page. Returns a User or a NullPage.  
created_users_id int ID of created user.  
modifiedUser User NullPage The user that last modified this page. Returns a User or a NullPage.  
modified_users_id int ID of last modified user.  

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.251