pre_wp_update_comment_count_now
Filter HookDescription
Filters a post's comment count before it is updated in the database.Hook Information
File Location |
wp-includes/comment.php
View on GitHub
|
Hook Type | Filter |
Line Number | 2806 |
Hook Parameters
Type | Name | Description |
---|---|---|
int|null
|
$new
|
The new comment count. Default null. |
int
|
$old
|
The old comment count. |
int
|
$post_id
|
Post ID. |
Usage Examples
Basic Usage
<?php
// Hook into pre_wp_update_comment_count_now
add_filter('pre_wp_update_comment_count_now', 'my_custom_filter', 10, 3);
function my_custom_filter($new, $old, $post_id) {
// Your custom filtering logic here
return $new;
}
Source Code Context
wp-includes/comment.php:2806
- How this hook is used in WordPress core
<?php
2801 *
2802 * @param int|null $new The new comment count. Default null.
2803 * @param int $old The old comment count.
2804 * @param int $post_id Post ID.
2805 */
2806 $new = apply_filters( 'pre_wp_update_comment_count_now', null, $old, $post_id );
2807
2808 if ( is_null( $new ) ) {
2809 $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) );
2810 } else {
2811 $new = (int) $new;
PHP Documentation
<?php
/**
* Filters a post's comment count before it is updated in the database.
*
* @since 4.5.0
*
* @param int|null $new The new comment count. Default null.
* @param int $old The old comment count.
* @param int $post_id Post ID.
*/
Quick Info
- Hook Type: Filter
- Parameters: 3
- File: wp-includes/comment.php
Related Hooks
Related hooks will be displayed here in future updates.