OK, quick update...
The code pasted below, is now working out what the url should be that the user should be redirected to as I can see it rendered in the output. However, 1 more thing... It is not including the #[[+id]] element that I need added to the end of the URL to redirect to - so instead of it outputing
http://www.example.com/here/ I need it to be
http://www.example.com/here/#67 if the page id of the resource was 67.
Any ideas?? Thanks Bob!
$thisId = $modx->resource->get('id');
$ids = array_reverse($modx->getParentIds($thisId));
$ids[] = $thisId;
$i = 1;
$level = $modx->resource->getTVValue('levelsUp');
$output = '<p>In snippet id = ' . $thisId . '</p>';
foreach ($ids as $id => $value) {
$docIds[$i] = $value;
if ($value == $thisId) {
$target = $docIds[$i - $level];
if (!empty($target)) {
$url = $modx->makeUrl($target, "", "", "full");
if (!empty($url)) {
$output .= '<p>URL: ' . $url;
// $modx->sendRedirect($url);
} else {
$output .= '<p>URL is empty<br>Level is ' . $level . '<br> i is ' . $i . '</p>';
}
} else {
$output .= '<p>Target is empty<br>Level is ' . $level . '<br> i is ' . $i . '</p>';
}
}
$i++;
}
$output .= '<br><pre>' . print_r($ids, true) . '</pre>';
return $output;
return $thisId;