Tom. Posted May 9, 2016 Share Posted May 9, 2016 Hello, I was wondering if there is a simpler way of sorting like this using the API selector: $items = $page->children("sort=title"); $featured = new PageArray(); $featured->add($items); $items->prepend($featured->filter("featured=1")->sort("timeon")); Basically I'm wanting anything that's featured to filter by the time the artist is playing ("TimeOn") and for the rest to filter by title. I know above isn't exactly bloated, but I was just wondering if there is something simpler? Maybe a way of doing this inside the selector. This method is quite nice because ProcessWire automatically removes duplicates so it orders perfectly. Link to comment Share on other sites More sharing options...
arjen Posted May 9, 2016 Share Posted May 9, 2016 You can sort multiple like this: $page->children("featured=1, sort=title, sort=timeon"); 3 Link to comment Share on other sites More sharing options...
szabesz Posted May 9, 2016 Share Posted May 9, 2016 It seems to be covered by the docs: https://processwire.com/api/selectors/#sort 1 Link to comment Share on other sites More sharing options...
Tom. Posted May 9, 2016 Author Share Posted May 9, 2016 You can sort multiple like this: $page->children("featured=1, sort=title, sort=timeon"); Sorry maybe I wasn't clear: Any child that is featured=1 will be sorted by the time they are on, and any child that isn't featured will be ordered alphabetically. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 9, 2016 Share Posted May 9, 2016 That's not possible in a single selector. Sort order can only be 'hierarchical' for the whole result set and not different for just a subset. 3 Link to comment Share on other sites More sharing options...
Robin S Posted May 10, 2016 Share Posted May 10, 2016 I was wondering if there is a simpler way of sorting like this using the API selector: $items = $page->children("sort=title"); $featured = new PageArray(); $featured->add($items); $items->prepend($featured->filter("featured=1")->sort("timeon")); I doubt it makes much (or any) difference in terms of performance but you can do the same a bit more briefly like this: $items = $page->children("sort=title"); $items->prepend($items->find("featured=1, sort=timeon")); 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 10, 2016 Share Posted May 10, 2016 There shouldn't be any difference as both are essentially the same. find() does internally create a new PageArray anyways. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now