I have a pretty high profile site we run off of EE and we have been using the sort on multiple columns ability of EE for quite some time. After upgrading to EE 1.6.4 (from 1.6.3) this afternoon we immediately noticed the sorting was all goofy.
Here are the details…
Example weblog tag:
{exp:weblog:entries weblog="main" status="open" limit="10" disable="member_data|pagination|trackbacks" orderby="weight|date" sort="asc|desc"}
{title} - {entry_date format="%D %d %M %Y %h:%i %A"} PST
{/exp:weblog:entries}
We would expect from that to get would be any articles marked as Important or Featured first as per the custom field then any articles marked regular after that. Then those articles should be sorted by date with the most recent ones at the top. This is the behavior we got previous to 1.6.4.
Instead we got entries from 2003 (our earliest date) all of which are marked as Regular and thus we would expect to not even show since they wouldn’t show if things are being sorted by entry_date desc as we expect.
I turned on the SQL Query display and saw that this query was being used to grab the entries:
SELECT t.entry_id, t.title FROM exp_weblog_titles AS t LEFT JOIN exp_weblogs ON t.weblog_id = exp_weblogs.weblog_id LEFT JOIN exp_weblog_data AS wd ON t.entry_id = wd.entry_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id WHERE t.entry_id !='' AND t.site_id IN ('1') AND t.entry_date < 1215047855 AND (t.expiration_date = 0 || t.expiration_date > 1215047855) AND exp_weblogs.is_user_blog = 'n' AND (t.weblog_id = '1' OR t.weblog_id = '7' ) AND t.status = 'open' AND t.status != 'closed' ORDER BY t.sticky desc, wd.field_id_26 asc, t.entry_id desc, t.entry_date desc, t.entry_id desc LIMIT 0, 10
The issue is obviously the ORDER BY portion:
ORDER BY t.sticky desc, wd.field_id_26 asc, t.entry_id desc, t.entry_date desc, t.entry_id desc LIMIT 0, 10
When I remove the t.entry_id desc but from behind the custom field being sorted by we get the expected results from the query. If I put it back in we don’t. So I chased that down to line 2602 of mod.weblog.php.
I changed this:
$end .= " {$sort_array[$key]}, t.entry_id {$sort_array[$key]}";
To this:
$end .= " {$sort_array[$key]}";
And problem solved. Except that I’m sure you guys made that change for a reason.
So while this solves our immediate issue I’d love to get it solved officially or be corrected in terms of how I’m using this so I don’t have to worry about future upgrades.
Jamie
