Abubakar Abubakar - 1 month ago 7
PHP Question

Retrive Total Comments by post ID using wpdb query in Wordpress

I have two questions:


  1. Count total number of comments (Without Post Author & Child Comments) by Post ID using wpbd query.

  2. Get Last 3 comment author (without Post Author & Child Comments) by Post ID using wpdb query.



If you have any idea please help me.

Answer

Try this -

<?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);
?>