基于akTed\'s答案:
function get_top_level_comments_number( $post_id = 0, $onlyapproved = true ) {
global $wpdb, $post;
$post_id = $post_id ? $post_id : $post->ID;
$sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_parent = 0 AND comment_post_ID = $post_id";
if( $onlyapproved ) $sql .= " AND comment_approved=\'1\'";
return (int) $wpdb->get_var( $sql );
}
用法与相同
here … 返回特定帖子的顶级评论数(如果未提供id,则返回当前评论数)