Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
get_approved_comments() - 检索文章的已批准评论 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / get_approved_comments()

get_approved_comments( int $post_id, array $args = array() )

检索文章的已批准评论


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "8a120dc4a793b62501729a9a51316687" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

comment 评论more...


参数

$post_id

(int) (必填) 文章的 ID

$args

(array) (可选) 有关可接受参数的信息,请参阅WP_Comment_Query::__construct()。

默认值: array()


返回

(WP_Comment[]|int[]|int) 批准的评论,或者如果$count参数为true,返回评论的数量。



源码

查看源码 官方文档


更新日志

版本描述
4.1.0重构利用WP_Comment_Query而非直接查询
2.0.0开始引入

使用示例

  • 示例1

    示例

    在本例中,我们将输出一个简单的评论ID列表和相应的文章ID。

    <?php
       $postID = 1;
       $comment_array = get_approved_comments($postID);
    
       foreach($comment_array as $comment){
          echo $comment->comment_ID." => ".$comment->comment_post_ID."\n";
       }
    ?>