如何在 WordPress 中获取 Post 的最新评论?

How to Get Latest Comment of a Post in WordPress?

我要获取post的最新评论。我的意思是,最近的评论。我试过以下代码。但它returns没什么。它是空的。

$args = array(  
    'number' => '1',
    'post_id' => $post->ID
);
$comments = get_comments($args);
echo $comments->comment_content; 

但是 post 有超过 3 条评论。

试试这个代码:

<?php 
    $args = array(
            'number' => '1',
            'post_id' => $post->ID
    );
    $comments = get_comments($args);
    foreach($comments as $comment) :
        echo $comment->comment_content;
    endforeach;
?>

试试这个:

<?php 
    $args = array(
        'post_id' => $post->ID,
        'orderby' => array('comment_date'),
        'order' => 'DESC',
        'number' => 1
    );
    $comment = get_comments( $args );
    echo $comment[0]->comment_content;
?>