Support » Fixing WordPress » Comments listed most recent first

  • I’ve spent at least an hour or so typing in different search strings to see if the answer already exists, and it must be one of those days.
    How do I change the comment sort order to descending by date?
    Thanks in advance!
    David McKay

Viewing 9 replies - 1 through 9 (of 9 total)
  • Mark (podz)


    Support Maven

    I thought comments were listed by when they are posted, so that will automatically be by time / date ?
    Unless I’ve misunderstood you…

    They are listed by when the date/time posted in ascending order. I need them to be in descending order, so that the most recent post is at the top and the oldest post is at the bottom.
    I just converted from MT, and for some reason I can’t locate the sort order function for WordPress.
    David McKay

    In wp-comments.php and in wp-comments-popup.php, you’ll find this string :

    $comments = $wpdb->get_results(“SELECT * FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = ‘1’ ORDER BY comment_date”);

    This is where the ORDER BY is declared. But I don’t know how to reverse that order. I suggest a little of Google.

    Aha! I’ve already been googling, buuuuut, with your help I changed the google to “php order by descending”, and amazingly, all I had to add was “ORDER BY comment_date DESC”.
    Thank you!
    This seems like it would be a common request, perhaps WordPress should make it a how to…
    David McKay

    Mark (podz)


    Support Maven

    You could write it up for the Wiki ? 🙂

    Is there a way for 1.5?

    Is there a way to implement this selectively on a category-per-category basis in 1.5? (so that if (in(category(x)) then DESC and else ASC)

    Would be nice feature to have the sort order as an optional argument to the call to comments_template(). Then you could just setup different templates depending on which order you want.

    FYI. In WP 1.5 you’ll only need to modify one file, in wp-includes/comment-functions.php near the top of this file is a function, “comments_template”.

    To sort ASC (ascending) or DESC (descending) add it to both queries in that function (it’s fairly obvious, only two SELECTS in this function)

    " ORDER BY comment_date DESC"

    By default “ASC” is implied, so these two statements are equivalent:

    " ORDER BY comment_date"
    " ORDER BY comment_date ASC"

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Comments listed most recent first’ is closed to new replies.