We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49438
    • 8 Posts
    I have a container with resources created in alphabetical order. (They are in ascending order of ID as well). I am retrieving them via the following code.

    $pagecontainer = $modx->getObject('modDocument', array('pagetitle'=>'library'));
    $pages = $pagecontainer->getMany('Children');
     foreach ($pages as $buildpage)
    do stuff... (Select pages on a certain criteria)
    


    The problem is in the output list where the selected resources are appearing in a random order and not in asceding order alphabetically or numerically based on ID. I would presume that the $pages array would contain them in sort order and the foreach loop would start from the beginning.

    Is there something which I am not doing correctly here? I am stumped by it. Thanks for the help in advance!

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 22840
      • 1,572 Posts
      If these are all children of a container is there any reason why your not using getResources or PDO tools for this ?
        • 49438
        • 8 Posts
        Hi Paul,

        Thanks for the reply. getResources wasn't exacly working for me as I have a complex selection criteria for the pages in foreach loop. I am relatively new to MODx so haven't had much exposure to PDO tools. If only I can sort these pages before entering the foreach loop, it would solve my problem. Is there any PDO tool which could help me out here?

        • discuss.answer
          • 4172
          • 5,888 Posts
          What Paul said.

          And you can send a criteria-object with getMany

          $pagecontainer = $modx->getObject('modDocument', array('pagetitle'=>'library'));
          $c = $modx->newQuery('modResource');
          $c->sortby('pagetitle');
          $pages = $pagecontainer->getMany('Children',$c);


            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 49438
            • 8 Posts
            Quote from: Bruno17 at Apr 14, 2015, 06:17 AM
            What Paul said.

            And you can send a criteria-object with getMany

            $pagecontainer = $modx->getObject('modDocument', array('pagetitle'=>'library'));
            $c = $modx->newQuery('modResource');
            $c->sortby('pagetitle');
            $pages = $pagecontainer->getMany('Children',$c);



            Hi Bruno. That's perfect! Exactly what I wanted. I haven't had a look into PDO queries till now but I will surely give it a go now. Thanks a ton for the quick response. Thanks to Paul as well.