Plugin Author
kjmtsh
(@kjmtsh)
Thank you for the report, ech3.
Yes, your assumption is right. I seem to slip in the code PHP ver 5.2.x doesn’t execute. Could you edit query.class.php, please?
Open the file with your favorite editor and go down to the line 769. You will find the code like below.
$compare = function($a, $b) {
global flipped;
return flipped[$a->ID] - flipped[$b-ID];
};
usort($results, $compare);
}
$wpdb->dbh->pre_ordered_results = $results;
}
}
Comment out the four lines (add two backslashes for each line), change the usort()’s arguments and add a new function at the end of it, just like below:
// $compare = function($a, $b) {
// global flipped;
// return flipped[$a->ID] - flipped[$b-ID];
// };
usort($results, array($this, 'orderby_callback'));
}
$wpdb->dbh->pre_ordered_results = $results;
}
}
private function orderby_callback($a, $b) {
global flipped;
return flipped[$a->ID] - $flipped[$b->ID];
}
With this change, PHP 5.2.x will execute without errors.
I’ll commit the change for the next release, but the date is uncertain. I hope this will help you.
Thread Starter
ech3
(@ech3)
I ended up having to add a dollar sign before the orderby_callback function’s flipped variable in a couple of places to get it to work. Below is the diff I used.
[Edit – Reversed the diff to the correct direction]
--- query.class.php.orig 2014-09-12 06:21:17.802511000 -0400
+++ query.class.php 2014-09-12 06:11:27.503756000 -0400
@@ -766,15 +766,20 @@
$_wpdb = new PDODB();
$results = $_wpdb->get_results($query);
$_wpdb = null;
- $compare = function($a, $b) {
- global $flipped;
- return $flipped[$a->ID] - $flipped[$b->ID];
- };
- usort($results, $compare);
+ //$compare = function($a, $b) {
+ //global $flipped;
+ //return $flipped[$a->ID] - $flipped[$b->ID];
+ //};
+ //usort($results, $compare);
+ usort($results, array($this, 'orderby_callback'));
}
$wpdb->dbh->pre_ordered_results = $results;
}
}
+ private function orderby_callback($a, $b) {
+ global $flipped;
+ return $flipped[$a->ID] - $flipped[$b->ID];
+ }
/**
* Method to avoid DELETE with JOIN statement.
*