WordPress.org

Ready to get started?Download WordPress

Forums

Comments listed most recent first (10 posts)

  1. davidmckay
    Member
    Posted 9 years ago #

    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

  2. Mark (podz)
    Support Maven
    Posted 9 years ago #

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

  3. davidmckay
    Member
    Posted 9 years ago #

    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.
    Thanks,
    David McKay

  4. chiensavant
    Member
    Posted 9 years ago #

    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.

  5. davidmckay
    Member
    Posted 9 years ago #

    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

  6. Mark (podz)
    Support Maven
    Posted 9 years ago #

    You could write it up for the Wiki ? :)

  7. Jenniferr
    Member
    Posted 9 years ago #

    Is there a way for 1.5?

  8. yokima
    Member
    Posted 9 years ago #

    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)

  9. toastk
    Member
    Posted 8 years ago #

    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.

  10. Buz Carter
    Member
    Posted 8 years ago #

    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"

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags