Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created September 9, 2013 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remcotolsma/6493015 to your computer and use it in GitHub Desktop.
Save remcotolsma/6493015 to your computer and use it in GitHub Desktop.
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