patch for posts displaying in reverse order
-
OK, I’ve found a workaround for this issue for folks like me who are running older versions of WordPress, have had problems upgrading, and whose hosting providers won’t upgrade to a non-GA release of MySQL to fix the problem.
Note: This isn’t 100% guaranteed not to cause problems. It’s working for me but YMMV.
In wp-includes/classes.php, look for this line:
$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";
Change it to this:
if (trim($groupby)=="$wpdb->posts.ID") { $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " ORDER BY " . $orderby . " $limits"; } else { $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits"; }
In other words, if we’re only doing a GROUP BY on the primary key of the posts table, there’s no need for the GROUP BY, so just take it out.
This will cause problems with the query that supports the “previous posts” link, so make this change in template-functions-links.php:
In the “posts_nav_link” function, change this line:
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
… to this:
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
This is working fine for me so far. Hope it helps someone.
- The topic ‘patch for posts displaying in reverse order’ is closed to new replies.