Clarity Posted February 14, 2023 Share Posted February 14, 2023 Hello everyone! I have a paginated PageArray and I need to sort the results first by template1, then by template2 and template3 (in any order inside 2 and 3). Then by other templates by any order. Can you please tell me how to do it? The solution might look something like: $pages->find('sort=(template=template1,template=template2|template3),...'); Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted February 14, 2023 Share Posted February 14, 2023 https://processwire.com/docs/selectors/#sort 1 Link to comment Share on other sites More sharing options...
Robin S Posted February 14, 2023 Share Posted February 14, 2023 14 hours ago, Clarity said: The solution might look something like: $pages->find('sort=(template=template1,template=template2|template3),...'); PW doesn't support that kind of sorting in $pages->find(), but you could use the FindMerge module and do something like this: $base_selector = "title=foo"; $selectors = [ "$base_selector, template=template1", "$base_selector, template=template2|template3", "$base_selector, template!=template1|template2|template3", ]; $pagination_limit = 20; $results = $pages->findMerge($selectors, $pagination_limit); 2 2 Link to comment Share on other sites More sharing options...
Clarity Posted February 15, 2023 Author Share Posted February 15, 2023 8 hours ago, Robin S said: PW doesn't support that kind of sorting in $pages->find(), but you could use the FindMerge module and do something like this: $base_selector = "title=foo"; $selectors = [ "$base_selector, template=template1", "$base_selector, template=template2|template3", "$base_selector, template!=template1|template2|template3", ]; $pagination_limit = 20; $results = $pages->findMerge($selectors, $pagination_limit); Thank you, it indeed works! 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