Sort-Problem with WordPress on Debian Etch, mySQL 5.0.51a

Yesterday we updated our Debian-Etch-server via apt-get (the only new software was mySQL 5.0.51a) and got an very ugly problem with WordPress. Now all sites with attributes is_home or is_date (Home and Archives) are sorted in wrong direction. That means that in this cases oldest entries are listed first. At time we don’t know exactly what to do :mrgreen: I allready searched for the function(s) which are responsible for generating the specific sites. In the file functions.php is a function get_posts($args) which contains a nice SELECT but don’t know which other function use this and all (?) other functions there are also not responsible for the problem.

Interesting is that a simple

SELECT * FROM `wp_posts` WHERE `post_status`=’publish’ ORDER BY `post_date_gmt` DESC LIMIT 10

in myPHP shows the normal and correct answer. This means that somewhere in WordPress must be a SQL-phrase with a syntax that is not right for the actual Debain Etch stable or rather the installed mySQL-version :| Anyone knows how to locate the problem? :roll:

3 responses to “Sort-Problem with WordPress on Debian Etch, mySQL 5.0.51a”

  1. admin

    I have found a solve for the problem:
    In mySQL 5.0.51 a query with a GROUP BY ignors the subsequent ORDER BY clause if the argument of GROUP BY is the primary key and in some other circumstances with a GROUP-BY on one row. That’s fixed by version 5.0.52 and there exists some (not really nice) workarounds for 5.0.51. Here are the options:
    - upgrade your mySQL
    - upgrade to the new WordPress 2.5
    - rewrite in wordpress the queries with GROUP BY id in GROUP BY post_date
    - delete the GROUP BY in cases where you don’t need them or make a use braces for an interlocked sql-query

    mhh, now I’m wondering why a buggy mySQL-version is published in Debian stable, that’s not normal … But who cares, I’m going on to fix the problem in my blogs temporarily, cause don’t have root-rights and my friend who ownes the server is sleeping …

  2. admin

    Older WP-versions and forks have the problem located in /wp-includes/classes.php at the end of function &get_posts(). There is a line

    $request = ” SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1″ . $where . ” GROUP BY ” . $groupby . ” ORDER BY ” . $orderby . ” $limits”;

    Some lines above you’ll find $groupby = ” $wpdb->posts.ID “;. Change this into $groupby = ” post_date “; and in mostly all circumstances you got the right response from your blog. Actually I don’t know any query where you need the ORDER BY id, but some plugins could use it. Of course you’ll lose articles with exactly the same Date&Time. So it’ll be better to change the code back after updating your mySQL-server.

  3. admin

    I had wondered about the fact, that Debain stable used a buggy mySQL-version and I was right with wondering ;) Yesterday I talked to my friend who’s administrating this server and he told me, that he use the unofficial Dotdeb-repository for fresh (and in this case buggy *g*) web-packages ;) The official Debian-Etch-repository delivers momentary the older mySQL-version 5.0.32-7