Jump to main content Jump to doc navigation


Get an option value for this instance of an xPDOObject, using xPDO options if no instance specific option exists.


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

mixed getOption (string $key [, array|null $options [, mixed $default [, boolean $skipEmpty]]] )
  • $key: the key of the setting or option to load.
  • $options: the source of the setting or option. Either null (which attempts to find the key in the main configuration) or an array of options.
  • $default: the value to return when the key was not found.
  • $skipEmpty: when set to true, the $default will also be returned if the $key's value is an empty string. Added in xPDO 2.2.1 / MODX 2.2.0-rc2.


Simple Option Retrieval

Gets the config setting for xPDO::OPT_HYDRATE_FIELDS.

$hydrateFields = $xpdo->getOption(xPDO::OPT_HYDRATE_FIELDS);

Gets the config option for 'test', and if not set, returns '123'.

$test = $xpdo->getOption('test',null,'123');

Checks the $props array for the key 'depth', and if doesn't exist, then checks $xpdo->config, and if still doesn't exist, then sets to 10.

$props = array();
$depth = $xpdo->getOption('depth',$props,10);
echo $depth; // prints 10

$depth = $xpdo->getOption('depth',$props,10);
echo $depth; // prints 20

$props['depth'] = 30;
$depth = $xpdo->getOption('depth',$props,10);
echo $depth; // prints 30

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.


  • modmore
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Digital Penguin
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • Following Sea
  • Anton Tarasov
  • eydolan
  • Raffy
  • Lefthandmedia
  • Murray Wood
  • Nick Clark
  • Snow Creative
  • Helen
  • JT Skaggs
  • krisznet
  • YJ
  • Yanni
  • Richard


$371 per month—let's make that $500!

Learn more