Filter hook 'wp_count_comments'

in WP Core File wp-includes/comment.php at line 1462

View Source

wp_count_comments

Filter Hook
Description
Filters the comments count for a given post or the whole site.

Hook Information

File Location wp-includes/comment.php View on GitHub
Hook Type Filter
Line Number 1462

Hook Parameters

Type Name Description
array|stdClass $count An empty array or an object containing comment counts.
int $post_id The post ID. Can be 0 to represent the whole site.

Usage Examples

Basic Usage
<?php
// Hook into wp_count_comments
add_filter('wp_count_comments', 'my_custom_filter', 10, 2);

function my_custom_filter($count, $post_id) {
    // Your custom filtering logic here
    return $count;
}

Source Code Context

wp-includes/comment.php:1462 - How this hook is used in WordPress core
<?php
1457  	 * @since 2.7.0
1458  	 *
1459  	 * @param array|stdClass $count   An empty array or an object containing comment counts.
1460  	 * @param int            $post_id The post ID. Can be 0 to represent the whole site.
1461  	 */
1462  	$filtered = apply_filters( 'wp_count_comments', array(), $post_id );
1463  	if ( ! empty( $filtered ) ) {
1464  		return $filtered;
1465  	}
1466  
1467  	$count = wp_cache_get( "comments-{$post_id}", 'counts' );

PHP Documentation

<?php
/**
	 * Filters the comments count for a given post or the whole site.
	 *
	 * @since 2.7.0
	 *
	 * @param array|stdClass $count   An empty array or an object containing comment counts.
	 * @param int            $post_id The post ID. Can be 0 to represent the whole site.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/comment.php
Related Hooks

Related hooks will be displayed here in future updates.