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.
Parameters
$post_idint|null
Post ID.
$do_deferredbooloptional
Whether to process previously deferred post comment counts. Default false.Default: false
Return
bool|void
True on success, false on failure or if post with ID does not exist.
2812functionwp_update_comment_count($post_id,$do_deferred=false){2813static$_deferred=array();28142815if(empty($post_id)&&!$do_deferred){2816returnfalse;2817}28182819if($do_deferred){2820$_deferred=array_unique($_deferred);2821foreach($_deferredas$i=>$_post_id){2822wp_update_comment_count_now($_post_id);2823unset($_deferred[$i]);2824/** @todo Move this outside of the foreach and reset $_deferred to an array instead */2825}2826}28272828if(wp_defer_comment_counting()){2829$_deferred[]=$post_id;2830returntrue;2831}elseif($post_id){2832returnwp_update_comment_count_now($post_id);2833}2834}
History
Introduced in 2.1.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.1.0
Return type changed from bool|void to bool|null.verified against source
2.1.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/comment.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.