getParentIds
Last edited by JP DeVries on Aug 9, 2013.
API:getParentIds
API Quick reference
Variable name: | getParentIds |
Modx versions: | 0.9.x + Evolution |
Variable type: | array |
Object parent: | DocumentParser |
Description
Array getChildIds(mixed $id[, int $height[, array $parents]]);
Returns an array of all parent record IDs for the id passed.
- $id - resource ID to get parents for
- $height - argument defines the maximum number of levels to go up.
- $parents - array ?
Usage / Examples
$parents = $modx->getParentIds(10);
will return an array of all the parents of document 10, starting at the lowest level and working upwards, using aliases as the array keys, e.g.
Array ( [services/accident-claims] => 3 [services] => 2 )
Related
Notes
Function Source
function getParentIds($id, $height= 10, $parents= array ()) { $parentId= 0; foreach ($this->documentMap as $mapEntry) { $parentId= array_search($id, $mapEntry); if ($parentId) { $parentKey= array_search($parentId, $this->documentListing); if (!$parentKey) { $parentKey= "$parentId"; } $parents[$parentKey]= $parentId; break; } } $height--; if ($parentId && $height) { $parents= $parents + $this->getParentIds($parentId, $height, $parents); } return $parents; }
Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).