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

Please follow and like us:
Published
Categorized as Wordpress

By Leendert

Leendert van Achteren is a Business Analyst and part-time Web Entrepreneur. He's building and managing websites with SEO in mind He's writing about anything that has his interest, but especially focusing on market transparency for consumers.

Leave a comment

Your email address will not be published. Required fields are marked *

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