Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress function/action to exclude comment type in comment count.
<?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
You can’t perform that action at this time.