Wordpress Hack: Sort Comments
Written by Saman Sadeghi on January 5, 2007 Add comments
I have been searching the net for a while for a way to sort comments on my blog, and have found the way to do it! We need to edit a core Wordpress file:
wp-includes/comment-functions.php
Remember: Any changes made to this file will need to be redone if you update Wordpress!
On line 16, we will find the following code:
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date");
The ORDER BY at the end is what we are concerned with. Wordpress has the following variables we can use:
- comment_ID
- comment_post_ID
- comment_author
- comment_author_email
- comment_author_url
- comment_author_IP
- comment_date
- comment_date_gmt
- comment_content
- comment_karma
- comment_approved
- comment_agent
- comment_type
- comment_parent
- user_id
You can learn more about Wordpress’ Databases on the Codex by clicking here.
Start Slide Show with PicLens LiteMegaman Loves These Related Posts:
[...] on, Samanathon posts about sorting comments in Wordpress blogs. These are the kind of articles I love. A few simple cut and paste code snippets and you’re [...]
In the new 2.5 you will have to look for the file here : wp-includes/comment.php
Around line 94 you will find this function :
function get_approved_comments($post_id) {global $wpdb;
return $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));
}
Change the comment_date to any of the options above!
[...] Wordpress Hack: Sort Comments | Samanathon.com I have been searching the net for a while for a way to sort comments on my blog, and have found the way to do it! We need to edit a core Wordpress file: (tags: wordpress hacks comments tutorials) [...]