craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 56 forks source link

Order results by two fields #127

Closed Stalex89 closed 3 years ago

Stalex89 commented 4 years ago

For example I need to sort out news topics first by top news (boolean), then by post date. So first I should have all top news ordered by post date, then all of the rest topics ordered by post date. Is it possible to output the results ordered by two fields ?

Something like that:

                'criteria' => [
                    'orderBy' => ['isOnTop' ,'postDate desc']
                ],
BeKnowDo commented 3 years ago

Did you resolve your issue?

MaartenVenema commented 3 years ago

I know this one is closed but if someone comes by this for some reason you can set multiple order commands by seperating them by a , so for example 'orderBy' => 'postDate asc, starttime asc'. Setting them as a array results in errors for me and this seems to work.