$page->get() method

Get the value of a Page property (see details for several options)

This method can accept a simple property name, and also much more:

  • You can retrieve a value using either $page->get('property'); or $page->property.
  • Get the first populated property by specifying multiple properties separated by a pipe, i.e. headline|title.
  • Get multiple properties in a string by specifying a string {property} tags, i.e. {title}: {summary}.
  • Specify a selector string to get the first matching child page, i.e. created>=today.
  • This method can also retrieve sub-properties of object properties, i.e. parent.title.
  • To get a guaranteed iterable value, append [] to the key, i.e. $page->get('name[]'). 3.0.205+

Example

// retrieve the title using get…
$title = $page->get('title');

// …or retrieve using direct access
$title = $page->title;

// retrieve headline if populated, otherwise title
$headline = $page->get('headline|title');

// retrieve title, created date, and summary, formatted in a string
$str = $page->get('{createdStr}: {title} - {summary}');

// example of getting a sub-property: title of parent page
$title = $page->get('parent.title');

// all following features are supported in 3.0.205+

// get value guaranteed to be iterable (array, WireArray, or derived)
$images = $page->get('image[]');
$categories = $page->get('category[]');

// get item by position/index, returns 1 item whether field is single or multi value
$file = $page->get('files[0]'); // get first file  (or null if files is empty)
$file = $page->get('files.first); // same as above
$file = $page->get('files.last'); // get last file
$file = $page->get('files[1]'); // get 2nd file (or null if there isn't one)

// get titles from Page reference field categories in an array
$titles = $page->get('categories.title');  // array of titles
$title = $page->get('categories[0].title'); // string of just first title

// you can also use a selector in [brackets] for a filtered value
// example: get categories with titles matching text 'design'
$categories = $page->get('categories[title%=design]'); // PageArray
$category = $page->get('categories[title%=design][0]'); // Page or null
$titles = $page->get('categories[title%=design].title'); // array of strings
$title = $page->get('categories[title%=design].title[0]'); // string or null

Usage

$mixed = $page->get(string $key);

Arguments

NameType(s)Description
keystring

Name of property, format string or selector, per the details above.

Return value

mixed

Value of found property, or NULL if not found.

See Also


$page methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #522
    In the 522nd issue of ProcessWire Weekly we'll check out the latest core updates, introduce a new module called File Mover, and more. Read on!
    Weekly.pw / 11 May 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • 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