$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.244

Latest news

  • ProcessWire Weekly #558
    In the 558th issue of ProcessWire Weekly we'll check out the blog post that introduces ProcessWire 3.0.244, share some recent ProcessWire highlights, and more. Read on!
    Weekly.pw / 18 January 2025
  • ProcessWire 3.0.244 new main/master version
    ProcessWire 3.0.244 is our newest main/master/stable version. It's been more than a year in the making and is packed with tons of new features, issue fixes, optimizations and more. This post covers all the details.
    Blog / 18 January 2025
  • Subscribe to weekly ProcessWire news

“The end client and designer love the ease at which they can update the website. Training beyond how to log in wasn’t even necessary since ProcessWire’s default interface is straightforward.” —Jonathan Lahijani