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.
2809functionwp_update_comment_count($post_id,$do_deferred=false){2810static$_deferred=array();28112812if(empty($post_id)&&!$do_deferred){2813returnfalse;2814}28152816if($do_deferred){2817$_deferred=array_unique($_deferred);2818foreach($_deferredas$i=>$_post_id){2819wp_update_comment_count_now($_post_id);2820unset($_deferred[$i]);2821/** @todo Move this outside of the foreach and reset $_deferred to an array instead */2822}2823}28242825if(wp_defer_comment_counting()){2826$_deferred[]=$post_id;2827returntrue;2828}elseif($post_id){2829returnwp_update_comment_count_now($post_id);2830}2831}
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.9.7 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.