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.
2743functionwp_update_comment_count($post_id,$do_deferred=false){2744static$_deferred=array();27452746if(empty($post_id)&&!$do_deferred){2747returnfalse;2748}27492750if($do_deferred){2751$_deferred=array_unique($_deferred);2752foreach($_deferredas$i=>$_post_id){2753wp_update_comment_count_now($_post_id);2754unset($_deferred[$i]);2755/** @todo Move this outside of the foreach and reset $_deferred to an array instead */2756}2757}27582759if(wp_defer_comment_counting()){2760$_deferred[]=$post_id;2761returntrue;2762}elseif($post_id){2763returnwp_update_comment_count_now($post_id);2764}2765}
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 6.8.8 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.