Get the ID of the "Root Resource", aka "Ultimate Parent", with slightly different feature set.
<?php
/*
* @author @sepiariver
*
* GPL license, no warranties, no liability, etc.
*
* USAGE EXAMPLE:
* [[rootResource? &toPlaceholder=`root_resource`]]
* //followed by something like
* [[getResources? &parents=`[[+root_resource]]` ... ]]
*
*/
$id = $modx->getOption('id', $scriptProperties, $modx->resource->get('id'));
$toPlaceholder = $modx->getOption('toPlaceholder', $scriptProperties, '');
$pids = array_reverse($modx->getParentIds($id));
$output = (isset($pids[1]) && !empty($pids[1])) ? $pids[1] : $id;
if (empty($toPlaceholder)) return $output;
$modx->setPlaceholder($toPlaceholder, $output);