Wordpress comments order with wp_list_comments()

According to Codex:

Setting 'reverse_top_level' to true will display the most recent comment first then going back in order, and setting this to false will show the oldest comments first. If not specified, it will use the value stored in the WordPress dashboard settings.

My code:

 $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = $comments_post_id AND comment_approved=1 ORDER BY comment_date DESC LIMIT $comments_per_page OFFSET $offset" ); wp_list_comments(array( 'reverse_top_level' => false, 'type' => 'comment', 'callback' => 'render_user_comment', 'style' => 'div' ), $comments); 

But it just does not work. Whatever I do. I played with ORDER BY and WP Discussion Settings. Only if I set 'reverse_top_level' to false, WP always displays the most recent comments first.

Did anybody face this issue?

Thank you.

2

1 Answer

You could try something like.

$args = array( 'post_id' => $comments_post_id, 'status' => 'approve', 'orderby' => 'comment_date', 'order' => 'DESC', 'number' => $comments_per_page, 'offset' => $offset ); //get the comments $comments = get_comments( $args ); 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like