使用Wordpress中的wpdb查询按帖子ID回复总评论

时间:2016-10-13 05:36:38

标签: php wordpress comments

我有两个问题:

  1. 使用wpbd查询按帖子ID计算评论总数(没有帖子作者和儿童评论)?
  2. 使用wpdb查询通过帖子ID获取最后3条评论作者(没有帖子作者和儿童评论)?
  3. 如果您有任何想法,请帮助我。

1 个答案:

答案 0 :(得分:0)

试试这个 -

<?php $args = array(
    'order' => 'DESC',
    'parent' => '0',
    'number' => '',
    'post_id' => get_the_ID(),
    'status' => 'approve', //hold, approve, all
    'count' => true
);
$total_number_of_comments = get_comments( $args );
echo $total_number_of_comments;
?>
<?php $args = array(
    'order' => 'DESC',
    'parent' => '0',
    'number' => '3',
    'post_id' => get_the_ID(),
    'status' => 'approve', //hold, approve, all
    'count' => false
);
$last_three_comments = get_comments( $args );
print_r($last_three_comments);
?>