Many bloggers complained that their posts begin appearing in reversed orders after their webhost upgraded to MySQL 5.0.5x. This is caused by a bug in the MySQL database server affecting versions 5.0.50, 5.0.51 and 5.0.51a  (MySQL Bug #30596).

The bug can be reproduced by any SQL Select command that couples both GROUP BY and ORDER BY clauses and does not affect WordPress alone.

The work around for this problem is outlined below:

1. Upgrade/Downgrade MySQL Server.

Probably not the best solution but yet since 5.0.51a is the most recent version so an upgrade would mean getting the release candidate version running on production. Downgrading to a version before 5.0.50 solves the problem, but could revive bugs fixed after 5.0.50.

2. Temporary fix: Edit /wp-includes/post.php

Locate a line that looks like the following:

function get_posts($args) {

Scroll down and a few lines just before “return $posts” you will see:

$query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;

Change it to:

$query .= " ORDER BY " . $orderby . ' ' . $order;

This would make your posts appear in the right order again.

Leave a Reply