Reverse comments in WordPress

A “guestbook” page in WordPress where comments can be made by visitors can function as a guestbook. In this case it will be nice to have the comments sorted descending instead of ascending on time. This is how you do that:

Download the file /wp-includes/comment-functions.php
Open it in Notepad or another plaintext editor.

At the top, around line 14 is this:
if ( empty($comment_author) ) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");

You need to put a DESC in there at the end, like so:
if ( empty($comment_author) ) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date DESC");

next, look down another couple of lines, and you’ll see another similar statement, the last bit of which is:
comment_approved = '0' ) ) ORDER BY comment_date");

Again, stick a DESC in there
comment_approved = '0' ) ) ORDER BY comment_date DESC");

Save, upload – and keep a note of what you’ve done for when you upgrade 🙂

source: http://wordpress.org/support/topic/57046

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.