2

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...

curveball
  • 4,320
  • 15
  • 39
  • 49
BennyLava
  • 179
  • 1
  • 2
  • 15

1 Answers1

2

try this:

$criteria = $modx->newQuery('modResource');
$criteria->sortby('FIELD(modResource.id, '.implode(',',$ids).' )', 'DESC');
$criteria->where(array(
    'id:IN' => $ids
));
$res = $modx->getCollection('modResource', $criteria);
Vasis
  • 2,281
  • 1
  • 16
  • 23