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!

19 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.
Most vape tanks come with a spare glass tank.
Someone essentially help to makoe serijously articles
I might state. That is the very first time I frequented your websige page and so far?
I amazed with thee research you made to create this particular publish amazing.
Magnificent process!
hello!,I love your writing so a lot! percentage we be in contact more approximately your post on AOL?
I require a specialist on this area to solve my problem.
Maybe that’s you! Taking a look forward to see you.
I think this is one of the so much significant info
for me. And i am satisfied studying your article.
But should remark on some common things,
The web site taste is perfect, the articles is really great :
D. Excellent process, cheers
[…] you to have a superb time on the market, they need it to be a protected experience for each you and Pandora promo codice the […]
Excellent way of telling, and nice paragraph to obtain data about my presentation subject
matter, which i am going to present in academy.
Super wpis, w sumie się z Tobą zgadzam, choć w niektórych aspektach bym polemizowała.
Na pewno ten blog zasługuje na uznanie. Jestem
pewna, że tu jeszcze wpadnę.
Thanks , I’ve recently been loooking ffor information approximately this topic foor a long time and yours is the greatest I have found out so far.
But, what concerning the conclusion? Are you certain concerning the source?
Feeel free too visit myy website :: Creative Branding Indonesia
I feel that is among the most vital information for me.
And i’m happy reading your article. However want to observation on few basic issues, The site taste is great, the articles is truly nice : D.
Excellent task, cheers
This is a really good tip especially to those fresh to the blogosphere.
Short but very precise information… Thank you for sharing this one.
A must read post!
What a information of un-ambiguity and preserveness of valuable knowledge on the topic
of unexpected feelings.
An impressive share! I have just forwarded this onto a coworker who had been conducting a little homework on this.
And he actually ordered me dinner because I stumbled upon it for him…
lol. So allow me to reword this…. Thank YOU for the meal!!
But yeah, thanks for spending some time to talk about this matter here on your web
page.
Thank you, I’ve just been searching for info about this suibject for ages andd yours is the greatest I’ve discovered so far.
However, wjat in regards to the bottom line?
Are you poswitive in regards to the supply?
I am realy delighted to read this weblog posts hich consists of plenty off helpful facts, thanks for providing such
statistics.
Thanks for finally talking about > WordPress comment sort order display order
ascending or descending 2.6 < Loved it!
Today, I went tto the beach with my children. I
found a sea shell and gave it to my 4 year old daughyter and said “You can hear the ocean if you put this to your ear.”
She placed the shell to her ear and screamed. There was a hermit ccrab inside and it
pinched her ear. She never wants to goo back! LoL I know thiis
is completely off topic but I haad tto tell someone!