API:getParent

From MODx Wiki
Jump to: navigation, search

Returns the parent record for the id passed.


Usage

  1. array getParent($id=-1, $active=1, $fields='id, pagetitle, description, alias, parent');

Examples

  1. $parent = $modx->getParent(55,1,'pagetitle');

will return the parent's pagetitle of the document 55 only if the parent is published.


  1. $parent = $modx->getParent(55,0,'id');

will return parent document's id even if is not published.

Source Code

File: manager/includes/document.parser.class.inc.php
Line: 1467
function getParent($pid= -1, $active= 1, $fields= 'id, pagetitle, description, alias, parent') {
        if ($pid == -1) {
            $pid= $this->documentObject['parent'];
            return ($pid == 0) ? false : $this->getPageInfo($pid, $active, $fields);
        } else
            if ($pid == 0) {
                return false;
            } else {
                // first get the child document
                $child= $this->getPageInfo($pid, $active, "parent");
                // now return the child's parent
                $pid= ($child['parent']) ? $child['parent'] : 0;
                return ($pid == 0) ? false : $this->getPageInfo($pid, $active, $fields);
            }
    }
Personal tools