A few days ago i had to make a minor change to my friend’s site, he wanted the latest comments to be right on top instead of the usual at the bottom of a page, so I had to re-arrange how the comments appeared and if for some reason you need this function all you have to do is a minor edit of /wp-includes/comment-template.php.
Original Code:
// TODO: Use API instead of SELECTs.
if ( $user_ID) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND (comment_approved = '1' OR ( user_id = '$user_ID' AND comment_approved = '0' ) ) ORDER BY comment_date");
} else 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");
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date");
}
Amazingly enough all you have to do is add a four letter word… DESC :
// TODO: Use API instead of SELECTs.
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“);
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results(“SELECT * FROM $wpdb->comments WHERE comment_post_ID = ‘$post->ID’ AND ( comment_approved = ‘1′ OR ( comment_author = ‘$author_db’ AND comment_author_email = ‘$email_db’ AND comment_approved = ‘0′ ) ) ORDER BY comment_date DESC“);
}
That’s it!
UPDATE: I fired up my Dreamwever and can confirm that you’ll find the code in just about line 290
If you enjoyed this post, make sure you subscribe to my RSS feed!
Related posts:




March 29th, 2008 at 9:28 pm
Remember this change bevor you do a wordpress update, because it is a system file which usualy gets overwritten in a full update.
March 30th, 2008 at 12:59 am
Hello,
i have tried to apply it but it does not work on my existing posts… i am using Wp 2.3.3…
April 4th, 2008 at 1:43 pm
If you don’t want to edit the core files, then you can use my Plugin to do it. http://sudarmuthu.com/wordpress/reverse-comments
All you have to do is to drop my Plugin the Plugin directory and then activate it, you don’t need to edit the theme or any of the core files.
April 10th, 2008 at 12:35 pm
hi moses, you can get the same result by using array_reverse php function to the $comments array before comment loop in comments.php file.
October 13th, 2008 at 8:11 am
thanks I working http://www.ucretsiztarot.com or http://www.kompozisyonornekleri.com my web site .Thakns
October 23rd, 2008 at 1:10 am
very nice blog
October 26th, 2008 at 11:08 am
Advertising dikantorku lagi ada lowongn nich untuk staf kantor ada yang minat?lumayan lo salerinya berkisar 800-1 juta, bisa sambil kuliah pula, yang minat sms ya…
di bandung
(HRD : Achmad setiady (022-93418777)
April 24th, 2009 at 4:36 pm
This is a good way to accomplish the task. I usually us wp ajaxed plugin to accomplish this task but, I will use this now since I will cut down on the load time without that plugin
Thanks a bunch.
May 1st, 2009 at 2:19 pm
qldl3zk9i5e52z45
个
May 12th, 2009 at 5:51 am
This is good way to complete our task easily…
Thanks for it but at some point it conflict otherwise good try…
May 20th, 2009 at 3:28 pm
I bumped into your site while looking for something else. Just wanted to point out what I did with reverse order in comments(http://www.chilligavva.com/2008/01/17/order-in-comments.html). I would be interested in figuring out how to paginate comments, for a said post/page.
Rgds..
June 15th, 2009 at 6:08 am
wery nice blog
thank you admin
June 30th, 2009 at 6:57 am
works like a charm.thnx a lot
July 6th, 2009 at 3:43 am
Hreat job! thanks mate for your kind assistance
July 23rd, 2009 at 8:27 pm
i have tried to apply it Thanks
July 30th, 2009 at 7:51 pm
Thanks for the code
October 1st, 2009 at 8:20 am
What if my code is
ORDER BY comment_date_gmt”, $post->ID, $user_ID));
instead?
How can it be changed?
Thanks in advance!
October 1st, 2009 at 2:52 pm
Currently the chunk of code is on line 844 in Wordpress 2.8.4
Thank you, great tip!
November 30th, 2009 at 2:59 am
wery nice blog
February 21st, 2010 at 6:30 am
,..] http://www.wpthemesplugin.com is other must read source on this issue,..]
April 11th, 2010 at 12:02 pm
Thanx for this well written article. But I had difficulty navigating through your website because I kept getting 502 bad gateway error. Just thought to let you know.
June 14th, 2010 at 7:06 pm
Thanks a lot. I’ve been searching google for the answer and this is exactly what i was looking for. Worked like a charm.
July 6th, 2010 at 1:32 pm
is there a way to bring up the post which has the latest comment on top? like in forums? plz advice..