a-ok Posted May 22, 2020 Share Posted May 22, 2020 Is it possible to sort a Wire/PageArray (I'm using the RepeaterMatrix) by a field's value? The order is defined by the order in the CMS but if I wanted to change that order, on the front-end, to follow a pageField selection is this possible? Each row has a pageField that allows the client to select a number of categories that defines that row's content. If the client selects 'Digital' for a row then is there a way, on the front end, to put all the rows with that category first (thus breaking the order)? I would then use a get request (?f=digital) to define when the order should change, but I'm just wondering if the sorting order change is possible. I could probably loop through the rows and remove/append but wondered if this was possible within a selector? Link to comment Share on other sites More sharing options...
kixe Posted May 22, 2020 Share Posted May 22, 2020 // find pages and sort $pages->find('sort=firstsortfield,sort=secondsortfield'); // Sort WireArray from newest to oldest $items->sort("-created"); // Sort WireArray by last_name then first_name $items->sort("last_name, first_name"); https://processwire.com/api/ref/wire-array/sort/ Link to comment Share on other sites More sharing options...
a-ok Posted May 22, 2020 Author Share Posted May 22, 2020 I ended up with... $modules = $page->modulesA; if ($input->get('f')) { $moduleFilter = $input->get('f'); $modulesWithFilter = $modules->find("projectsCategories.name={$moduleFilter}"); $modulesWithoutFilter = $modules->removeItems($modulesWithFilter); $modules = $modulesWithFilter->add($modulesWithoutFilter); } Link to comment Share on other sites More sharing options...
kixe Posted May 22, 2020 Share Posted May 22, 2020 I recommend to sanitize the input $moduleFilter = $sanitizer->pageName($input->get('f')); 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