Japanese TV Show: Cat Tape Tricks Windows Tip: Lock Workstation

Wordpress Hack: Sort Comments

Written by Saman Sadeghi on January 5, 2007 Add comments

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.

Start Slide Show with PicLens Lite PicLens
This post is filed in: Hacks, Windows Tips And Tricks, WordPress and has been viewed 1,671 views times.

Japanese TV Show: Cat Tape Tricks Windows Tip: Lock Workstation

Megaman Loves These Related Posts:


Megaman
  • WordPress Plugin: Tab Order Fix For Brian’s Threaded Comments
  • WP Plugin: Ajax Comments 2.0
  • WP Plugin: AuthImage
  • Windows Tip: Put Some Space In Your Start Menu
  • Vote For Me In The 2007 Bloggers Tournament, Take 2 Tournament!


  • RSS feed | Trackback URI

    3 Comments »

    Pingback by Hack your own PC! » Nice4Rice.com 2007-03-15 10:49:29

    MyAvatars 0.2

    [...] 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 [...]

     
    Comment by peter 2008-06-17 02:31:32

    MyAvatars 0.2

    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!

     
    Pingback by links for 2008-09-25 » Anidan Design 2008-09-25 15:20:43

    MyAvatars 0.2

    [...] 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) [...]

     

    Leave a Reply

    Name (required)
    E-mail (required - never shown publicly)
    URI
    Your Comment (smaller size | larger size)
    You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.
    Japanese TV Show: Cat Tape Tricks Windows Tip: Lock Workstation