Jump to main content Jump to doc navigation


Get a field value (or a set of values) by the field key(s) or name(s).


API Docs: http://api.modxcms.com/xpdo/om/xPDOObject.html#get

mixed get(
   string|array $k,
   [string|array $format = null],
   [mixed $formatTemplate = null]

Do not use the $format parameter if retrieving multiple values of different types, as the format string will be applied to all types, most likely with unpredicatable results. Optionally, you can supply an associate array of format strings with the field key as the key for the format array.


Get the name field value of the object.

$name = $object->get('name');
echo $name; // produces "Charles"

Get an array of values for multiple fields:

$names = $object->get(array('name_first','name_last'));
echo $names['name_first'].' '.$names['name_last'];
// produces "Charles Longbottom"