Created
December 20, 2016 11:44
-
-
Save mostafasoufi/4a1bdf0a623d31aa925a43836aeb1dc0 to your computer and use it in GitHub Desktop.
Get total (parrent & child) comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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