2154 | | $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) ); |
| 2154 | |
| 2155 | $bad_parents = array(); |
| 2156 | $_bad_parents = $wpdb->get_col( "SELECT comment_ID from $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved != '1'" ); |
| 2157 | |
| 2158 | do { |
| 2159 | $children = $wpdb->get_col( "SELECT comment_ID from $wpdb->comments WHERE comment_post_ID = $post_id AND comment_parent IN (" . implode( ',', array_map( 'intval', $_bad_parents ) ) . ")"); |
| 2160 | $bad_parents = array_merge($bad_parents, $_bad_parents, $children); |
| 2161 | $_bad_parents = array_unique($children); |
| 2162 | } while ( $children ); |
| 2163 | |
| 2164 | $bad_parent_query = null; |
| 2165 | if ($bad_parents = array_unique($bad_parents)) { |
| 2166 | $bad_parents = implode(',', array_map( 'intval', $bad_parents )); |
| 2167 | $bad_parent_query = " AND comment_parent NOT IN ($bad_parents)"; |
| 2168 | } |
| 2169 | |
| 2170 | $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'".$bad_parent_query, $post_id ) ); |