We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8416
    • 173 Posts
    Hello,
    I have this simple structure:

    Doc1
    -> Child1 (menu index 1)
    -> Child 2 (menu index 2)
    -> Child 3 (menu index 3)
    ......

    Is it possible from Doc1 to get the documnet ID of Child1 by specifying something like "get the child of document Doc1 whose menu index is 1. Is there an easy way to get it?
    Thanks
      • 22303 MODX Staff
      • 10,725 Posts
      The most efficient method would be using the getChildIds() function:
      <?php
      $children= $modx->getChildIds($documentId, 1);
      ?>

      which will get you an array of child document ids, and I believe it is in menuindex order. You could use this array in various ways to get specific elements. You can do the following to see what is available in the array and how the keys are structured
      <?php
      return '<pre>' . print_r($children, 1) . '</pre>';
      ?>

      This method does not require a database hit; it uses data that MODx already has available in memory during the request.
        • 8416
        • 173 Posts
        Thanks OpenGeek for your invaluable help!