MODX Community

Pdoresources: show resources in specified order (sorted by hand)

Hi!

How do I specify the exact order in which pdoresources lists the results?

I’d like to display a list with &resources=`9,3,6` and get resources 9,3 and 6 in that order. Possible?

This might work?

&sortby=`{id:9,3,6}`

If not, you can sort on any TV, so for instance can set the menu index for those resources to 1, 2, 3 respectively, and then use:

&sortby=`{menuindex:ASC}`

sortby=`{id:9,3,6}`

Nope, that throws an error:

Fatal error : Uncaught TypeError: Argument 1 passed to pdoFetch::replaceTVCondition() must be of the type array, null given

(Sorting with menuindex is no option here)

maybe

&sortby=`FIELD(modResource.id, 4,7,2,5,1 )` &sortdir=`ASC`

Maybe needs brackets?

sortby=`{id:[9,3,6]}`

Bingo! (strange, this was the first thing I tried and it did not work then … )

Thanks!

@lucy Sorry, still errors. But Brunos version works!

Awesome, glad you got it working. I just found it in the docs for getResources. I often forget to look there but I think there are more examples than in the pdoResources docs.

https://docs.modx.com/current/en/extras/getresources/index