We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29902
    • 72 Posts
    I have an array with id's:

    $ids = array(240, 12, 400);


    And I want to get those objects in that order with $modx->getCollection('modResource');

    How can I accomplish that?

    if I do like this:

    $res = $modx->getCollection('modResource', array(
        'id:IN' => $ids
    ));


    the boxes are in ASC order, but I want them in this order: 240, 12 400... [ed. note: thorjarle last edited this post 11 years, 6 months ago.]
      ...I believed it was Friday...
      • 4172
      • 5,888 Posts
      you can try something like that:

      $ids = '240,12,400';
      $classname = 'modResource';
      
      $c = $modx->newQuery($classname);
      $c->where(array('id:IN' => explode(',',$ids)));
      $c->sortby('FIELD(modResource.id, ' . $ids . ')'; 
      
      $res = $modx->getCollection($classname, $c);
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!