getChildIds

Last edited by JP DeVries on Aug 10, 2013.

Welcome to the MODX Documentation. It is an ongoing effort of the MODX community. If you would like to participate or if you notice any errors or missing content, please let us know.

API:getChildIds

API Quick reference
Variable name: getChildIds
Modx versions: 0.9.x + Evolution
Variable type: array
Object parent: DocumentParser

Description

Array getChildIds(mixed $id[, int $depth[, array $children]]);

Returns an array of child IDs belonging to the specified parent.

  • $id - the parent page to start from
  • $depth - how many levels deep to search for children
  • $children - if you already have an array of child ids, give it to the method, and new values will be added

Contains the document Listing (tree) like the sitemap

Usage / Examples

See also, this page on Understanding the Document Object

Notes

Function Source

    function getChildIds($id, $depth= 10, $children= array ()) {
        $c= null;
        foreach ($this->documentMap as $mapEntry) {
            if (isset ($mapEntry[$id])) {
                $childId= $mapEntry[$id];
                $childKey= array_search($childId, $this->documentListing);
                if (!$childKey) {
                    $childKey= "$childId";
                }
                $c[$childKey]= $childId;
            }
        }
        $depth--;
        if (is_array($c)) {
            if (is_array($children)) {
                $children= $children + $c;
            } else {
                $children= $c;
            }
            if ($depth) {
                foreach ($c as $child) {
                    $children= $children + $this->getChildIds($child, $depth, $children);
                }
            }
        }
        return $children;
    }