Jakub Linowski Posted February 4, 2022 Share Posted February 4, 2022 Hi, We've been using Processwire on GoodUI.org to display content (a/b test results) and we're hitting a roadblock as to how to filter multiple pages and sort by multiple repeaters. Our structure is more or less the following (with "S" meaning there are multiple tests and repeaters to cycle through) : TEST(S) REPEATER(S) METRIC EFFECT (In other words, a single test can have multiple repeaters which we'd like to check) We'd like to: 1. look up those TESTS that have any REPEATERS with a METRIC of X 2. sort those TESTS by the one REPEATER that has a METRIC of X, by it's EFFECT Can someone expert PHP / Processwire please help? This functionality is key in surfacing our best/top tests to the top which we'd like to enable and build out. Jakub Link to comment Share on other sites More sharing options...
BillH Posted February 5, 2022 Share Posted February 5, 2022 Welcome to the forums! There are various ways you could do this, if I understand what you're trying to achieve correctly, but I'd suggest something like the following (written without any testing): // Get a ProcessWire page array of pages with the X metric $testsWithX = $pages->find("repeater.metric=X"); foreach($testsWithX as $test) { // Set output formatting to false $test->of(false); // Get the relevant effect from the repeater $effect = $test->repeater->get("metric=X")->effect; // Set a sort property for the page (in the page array) $test->effect_for_sort = $effect; // Save (to the page array) $test->save('effect_for_sort'); } // Sort the array of pages $testsWithX->sort('effect_for_sort'); Looping through the pages shouldn't give you any issues with performance at all - unless you have a huge number of pages. One alternative would be to maintain a sort field (containing the relevant effect value) on each page, kept up to date by hooking on page save. Then you could get the sorted array of pages with a single selector. However, something like the above should be fine – and would in any case be a better approach while developing the site because it's easily amended. 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