a-ok Posted October 19, 2016 Share Posted October 19, 2016 What's the best way to sort two PageArrays by two separate keys using PW? I'm unsure if this is possible rather than using just PHP (but was curious to know if PW had such a way). I have a page, 'Designers', and I have three fields for the children pages... title, firstname and lastname. If the designer is a person then they fill out all three fields, but if they are a collective/group then they just fill out the title. My plan would be to then create two queries... one returning only the designers with full names (first and last) and then the other returning collective/groups only. $designers_person = $pages->find("parent=/designers/, designers_lastname!='', sort=designers_lastname"); $designers_group = $pages->find("parent=/designers/, designers_lastname='', sort=title"); What I then need to do is combine these two queries and sort them so there is an alphabetical order, for example... Anni Albers (person)Kate Blee (person) Tord Boontje (person)Commune (collective) Javier Mariscal (person) Studioilse (collective) Any thoughts? Link to comment Share on other sites More sharing options...
LostKobrakai Posted October 19, 2016 Share Posted October 19, 2016 $designers_person = $pages->find("parent=/designers/, designers_lastname!=''")->each(function($designer){ $designer->custom_sort = $designer->designers_lastname; }); $designers_group = $pages->find("parent=/designers/, designers_lastname=''")->each(function($collective){ $collective->custom_sort = $collective->title; });; $all = $designers_person->add($designers_group)->sort('custom_sort'); 9 1 Link to comment Share on other sites More sharing options...
a-ok Posted October 19, 2016 Author Share Posted October 19, 2016 6 minutes ago, LostKobrakai said: $designers_person = $pages->find("parent=/designers/, designers_lastname!=''")->each(function($designer){ $designer->custom_sort = $designer->designers_lastname; }); $designers_group = $pages->find("parent=/designers/, designers_lastname=''")->each(function($collective){ $collective->custom_sort = $collective->title; });; $all = $designers_person->add($designers_group)->sort('custom_sort'); This is nuts. I had no idea you could do this. Thank you! 1 Link to comment Share on other sites More sharing options...
joe_ma Posted October 19, 2016 Share Posted October 19, 2016 Wow, this is great! I've also got a sorting problem, maybe this could be achieved in a similar way? The problem is this: I need a list of pages, that contains elements from the respective parent page. Is there a way to sort the list by a field that is only in the parent page? Something like: $results = $pages->find("template=name-of-child-template, sort=parent->field-on-parent-template"); Link to comment Share on other sites More sharing options...
Robin S Posted October 19, 2016 Share Posted October 19, 2016 8 hours ago, joe_ma said: Is there a way to sort the list by a field that is only in the parent page? You nearly had it $results = $pages->find("template=name-of-child-template, sort=parent.field-on-parent-template"); 5 Link to comment Share on other sites More sharing options...
joe_ma Posted October 20, 2016 Share Posted October 20, 2016 Thanks Robin, exactly what I needed. Works like a charm. 1 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