We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    That would require a snippet, you would call it with an argument &parent=`[*parent*]`, then the snippet would have to get the parent of the given document. Something like
    $doc = $modx->getParent($parent);
    $gpId = $doc['parent'];
    return $gpid;
    

    Or... if you are using 0.9.5, with its DocumentMap, you could use getParentIds and select the second item in the resulting array. I haven’t worked with that feature yet, so I’m not sure how it would go. I’d want to take a look at that array with a print_r() of it. Probably something like this:
    $parents = $modx->getParentIds($modx->documentIdentifier);
    $grandparent = $parents[1]; // 0 would be parent, 1 would be grandparent, etc...
    return $grandparent;
    

    No need for an argument in the snippet call in this case.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 30537
      • 9 Posts
      Okay im trying to build that snippet.

      $parent = $modx->documentObject[’parent’]; //this works, $parent is the id of the parent
      $grandparent = $modx->getParent($parent); //this doesn’t work, $grandparent is NULL I can’t seem to get getParent() to return any values..