Code is PoetryI 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.