Skip to content

Instantly share code, notes, and snippets.

@mostafasoufi
Created December 20, 2016 11:44
Show Gist options
  • Save mostafasoufi/4a1bdf0a623d31aa925a43836aeb1dc0 to your computer and use it in GitHub Desktop.
Save mostafasoufi/4a1bdf0a623d31aa925a43836aeb1dc0 to your computer and use it in GitHub Desktop.
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