如何按降序对评论进行排序?

How can I sort comments in descending order?

我的 WordPress 评论模板有问题。

我想按降序对评论进行排序。

我尝试使用此代码,但没有用。

array ('order' => 'DESC')

评论模板:

<div class="wpcomments">
    <?php if(comments_open()) : ?>
        <div class="commentstyle">
            <?php if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) : ?>
                <?php die('You can not access this page directly!'); ?> 
            <?php endif; ?>
            <?php if(!empty($post->post_password)) : ?>
                <?php if($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
                    <p>This post is password protected. Enter the password to view comments.</p>
                <?php endif; ?>
            <?php endif; ?>
            <?php if($comments) : ?>
            <ol>
                <?php foreach($comments as $comment) : ?>
                    <li id="comment-<?php comment_ID(); ?>">
                        <div class="commentw">
                            <?php if ($comment->comment_approved == '0') : ?>
                                <p></p>
                            <?php endif; ?>
                            <div class="comment-avatar"></div>
                            <div class="comment-left"><b><?php comment_author_link(); ?></b> (<?php comment_date(); ?> <?php comment_time(); ?>)
                                <div class="comment-below">
                                    <?php comment_text(); ?>
                                </div>
                            </div>
                        </div>
                    </li>
                <?php endforeach; ?>
            </ol>
            <?php else : ?>
            <?php endif; ?>
        </div>
    <?php endif; ?>
</div>

尝试

'comments_array' hook in function.php

add_filter( 'comments_array' , 'shuffle_comments' , 10, 2 );

function shuffle_comments( $comments , $post_id ){ 
    return shuffle( $comments ); 
}

用于修改特定 post、

的结果

可以通过admin dashboard或SQL:

来完成
// SELECT * FROM wp_options WHERE option_name LIKE '%comment%'
UPDATE wp_options SET option_value='desc' WHERE option_name='comment_order'