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|null
True on success, false on failure or if post with ID does not exist.
3071functionwp_update_comment_count($post_id,$do_deferred=false){3072static$_deferred=array();30733074if(empty($post_id)&&!$do_deferred){3075returnfalse;3076}30773078if($do_deferred){3079$_deferred=array_unique($_deferred);3080foreach($_deferredas$i=>$_post_id){3081wp_update_comment_count_now($_post_id);3082unset($_deferred[$i]);3083/** @todo Move this outside of the foreach and reset $_deferred to an array instead */3084}3085}30863087if(wp_defer_comment_counting()){3088$_deferred[]=$post_id;3089returntrue;3090}elseif($post_id){3091returnwp_update_comment_count_now($post_id);3092}3093returnnull;3094}
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.1.0 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.