SportsPress
SportsPress copied to clipboard
League table custom sort issue with decimal values
In the sportspress/includes/class-sp-league-table.php file, lines 911 and 917, uasort expects 0 or 1 or -1, thus simply returning the value difference will give inconsistent results.
How to reproduce: Create a new league table, use a column with decimal places then add a difference smaller than 1 between items: e.g Team A: 5.28 Team B: 6.27
The ordering will be broken, because the function returns -0.99 instead of -1.
How to fix it:
A simple one line conditional statement should do it:
return ( (float) $b[ $this->orderby ] - (float) $a[ $this->orderby ] ) > 0 ? 1 : -1;
and
return ( (float) $a[ $this->orderby ] - (float) $b[ $this->orderby ] ) > 0 ? 1 : -1;
At least this fixes the issue for me. Cheers!
Or maybe even the simpler version return ($a < $b) ? -1 : 1;
should work, there's no need to subtract these 2
@rochesterj is that issue still there?