Created
September 9, 2013 08:38
-
-
Save remcotolsma/6493015 to your computer and use it in GitHub Desktop.
WordPress function/action to exclude comment type in comment count.
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 | |
/** | |
* Update comment count | |
* | |
* @see https://github.com/WordPress/WordPress/blob/3.6/wp-includes/comment.php#L1620 | |
*/ | |
function prefix_update_comment_count( $post_id ) { | |
global $wpdb; | |
$new = (int) $wpdb->get_var( $wpdb->prepare( " | |
SELECT | |
COUNT(*) | |
FROM | |
$wpdb->comments | |
WHERE | |
comment_post_ID = %d | |
AND | |
comment_approved = '1' | |
AND | |
comment_type != 'pronamic_like' | |
", $post_id | |
) ); | |
$wpdb->update( $wpdb->posts, array( 'comment_count' => $new ), array( 'ID' => $post_id ) ); | |
} | |
add_action( 'wp_update_comment_count', 'prefix_update_comment_count' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment