alexm Posted August 17, 2020 Share Posted August 17, 2020 Brains working at snails pace today... Is there a simple way of sorting results from a search by the pages with the most options in a page field multi select. e.g. you have a page field with Option 1, Option 2, Option 3 and Option 4. One page has all 4 selected, another 2 and another 1. I'd like to sort the search by the page with the most matching selected options first. Link to comment Share on other sites More sharing options...
MoritzLost Posted August 17, 2020 Share Posted August 17, 2020 You can use the count selector to get to the number of selected options, and use a descending sort order to show pages with the most selected items first: $results = $pages->find('sort=-categories.count'); Add the rest of your selectors and replace categories with the name of your page reference field ? See Using selectors in ProcessWire -> Count selectors. 2 1 Link to comment Share on other sites More sharing options...
alexm Posted August 17, 2020 Author Share Posted August 17, 2020 @MoritzLost cheers!! I did this and forgot to reverse like a sausage!! Thanks again ? 1 Link to comment Share on other sites More sharing options...
alexm Posted August 17, 2020 Author Share Posted August 17, 2020 @MoritzLost sorry, no, this hasn't quite achieved what I want actually. I don't want to list the page that has the most checked pages in a given page field, but a page that has the most matched checked pages based on a search parameter. e.g. if I search select (in a multi-select field) Option 1, Option 2 & Option 3 then the page with 4 selected options would show first then the next page that has the most matched checked pages. Does that make sense? Link to comment Share on other sites More sharing options...
alexm Posted August 17, 2020 Author Share Posted August 17, 2020 @MoritzLost IGNORE ME... Jeeeez. I'm having a meltdown today. Heavy weekend ? Thank you, thank you, thank you! 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