Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get total (parrent & child) comment
<?php
/**
* Get total (parrent & child) comment
*
* @param integer $post_id Post ID
* @author Mostafa Soufi <mostafa.soufi@hotmail.com>
*/
public function get_total_count( $post_id ) {
global $wpdb, $table_prefix;
$result = $wpdb->get_row( $wpdb->prepare("SELECT count(*) AS parrent_count, comment_ID AS last_parrent, ( SELECT COUNT(*) FROM ".$table_prefix."comments WHERE comment_parent = last_parrent AND comment_approved = '1' ) AS childs FROM ".$table_prefix."comments WHERE comment_post_ID = '%s' AND comment_approved = '1'", $post_id) );
if( $result ) {
return strval( $result->parrent_count + $result->childs );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.