On this page
wp_update_comment_count( int|null $post_id, bool $do_deferred = false ): bool|void
Updates the comment count for post(s).
Description
When $do_deferred is false (is by default) and the comments have been set to be deferred, the post_id will be added to a queue, which will be updated at a later date and only updated once per post ID.
If the comments have not be set up to be deferred, then the post will be updated. When $do_deferred is set to true, then all previous deferred post IDs will be updated along with the current $post_id.
See also
- wp_update_comment_count_now() : For what could cause a false return value
Parameters
$post_idint|null Required-
Post ID.
$do_deferredbool Optional-
Whether to process previously deferred post comment counts.
Default:
false
Return
bool|void True on success, false on failure or if post with ID does not exist.
Source
File: wp-includes/comment.php. View all references
function wp_update_comment_count( $post_id, $do_deferred = false ) {
static $_deferred = array();
if ( empty( $post_id ) && ! $do_deferred ) {
return false;
}
if ( $do_deferred ) {
$_deferred = array_unique( $_deferred );
foreach ( $_deferred as $i => $_post_id ) {
wp_update_comment_count_now( $_post_id );
unset( $_deferred[ $i ] );
/** @todo Move this outside of the foreach and reset $_deferred to an array instead */
}
}
if ( wp_defer_comment_counting() ) {
$_deferred[] = $post_id;
return true;
} elseif ( $post_id ) {
return wp_update_comment_count_now( $post_id );
}
}
Related
Uses
| Uses | Description |
|---|---|
| wp_update_comment_count_now() wp-includes/comment.php | Updates the comment count for the post. |
| wp_defer_comment_counting() wp-includes/comment.php | Determines whether to defer comment counting. |
Used By
| Used By | Description |
|---|---|
| wp_set_comment_status() wp-includes/comment.php | Sets the status of a comment. |
| wp_update_comment() wp-includes/comment.php | Updates an existing comment in the database. |
| wp_defer_comment_counting() wp-includes/comment.php | Determines whether to defer comment counting. |
| wp_insert_comment() wp-includes/comment.php | Inserts a comment into the database. |
| wp_delete_comment() wp-includes/comment.php | Trashes or deletes a comment. |
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_update_comment_count