WordPress comment sort order
Webmasters! Check out these money makers!!!!
Banned from Google? Check out this post!
Sort comment display order (ascending) ASC or (descending) DESC in WordPress 2.6.
I found this information on the web that was written about a year ago. Kudos to whomever hypOr is!
After searching through wp-includes/comment-template.php I found where to implement the mod. Works with my WP v2.6 no problem. However, when it comes time to upgrade your 2.6, you will have to do this again provided the future versions don’t change this one particular function. Future versions may even include this in the admin area. I hope.
Around line 642 in wp-includes/comment-template.php you need to add:
, $order = 'DESC' after:
$file = '/comments.php'
Example:
function comments_template( $file = '/comments.php', $order = 'DESC' ) No mods to these areas:
{
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
if ( ! (is_single() || is_page() || $withcomments) )
return;
$req = get_option('require_name_email');
$commenter = wp_get_current_commenter();
extract($commenter, EXTR_SKIP);
/** @todo Use API instead of SELECTs. */
if ( $user_ID) {
Then on ~lines 654, 656 and 658 add:
$order after:
ORDER BY comment_date
Example:
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )
ORDER BY comment_date $order", $post->ID, $user_ID));
} else if ( empty($comment_author) ) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'
ORDER BY comment_date $order", $post->ID));
} else {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) )
ORDER BY comment_date $order", $post->ID, $comment_author, $comment_author_email));
}
Or you can just replace the whole section if you want. Look carefully but, this should start at line 642 and end at line 659
function comments_template( $file = '/comments.php', $order = 'DESC' ) {
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
if ( ! (is_single() || is_page() || $withcomments) )
return;
$req = get_option('require_name_email');
$commenter = wp_get_current_commenter();
extract($commenter, EXTR_SKIP);
/** @todo Use API instead of SELECTs. */
if ( $user_ID) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date $order", $post->ID, $user_ID));
} else if ( empty($comment_author) ) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date $order", $post->ID));
} else {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date $order", $post->ID, $comment_author, $comment_author_email));
}
That’s it! Works for me…
Here is the link to where I found this.
After all that I found THIS. But, I have not tried it.
Webmasters! Check out these money makers!!!!
Banned from Google? Check out this post!
Get the kit HERE!

12 Responses to “WordPress comment sort order”
Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!











[...] through mine here you may want to check out these money makers!!!! You will also find a handy WordPress comment sort order tweak there too. All at [...]
This could work, but if you just want the sort to work for a specific theme, I suggest sticking to the comments.php.
I’ve found a quick fix that requires only a single line of code to be added on the comments.php to work.
I posted in my blog a short article on the solution to the worpdress comment sort.
Excellent solution. Thanks. I will have to try this. Way better than having to refer to notes on what to change with every PHPWS upgrade. Thanks for the post.
YOU ROCK, after using countless stupid mods that didnt work, i coded your text above and it fixed it ………!!
Hi there! Nice job You’re doing. If You would like to participate to our pay per click in-text program, please register. Regards
There is also a plugin available
http://wordpress.org/extend/plugins/comment-sorter/
Thanks dude!
It worked!
Tried a bunch of things, but this was the solution!!
Thanx once more!
I love your site.
Love design!!! I just came across your blog and wanted to say that I
Nontheless, citizens need to participate in decision-making about important issues and be provided with opportunities to deliberate with those who can inform the discussion. ,
works great !
Sign: zdbrw Hello!!! atwzv and 1233pmhmudwzku and 4409 : I love your site.
Love design!!! I just came across your blog and wanted to say that Ive really enjoyed browsing your blog posts.
Thank you for review a valuble article. This useful for me and my friend, I will follow your blog for continue reading your news.