更新帖子的评论计数。
原型
wp_update_comment_count( int|null $post_id, bool $do_deferred = false )
描述
当$ do_deferred为false(默认情况下)并且注释已设置为延迟时,post_id将添加到队列中,该队列将在以后更新,并且每个帖子ID仅更新一次。
参考:
- wp_update_comment_count_now()
参数
$post_id
(int|null)
(Required)
帖子ID。
$do_deferred
(bool)
(Optional)
是否处理先前延期的帖子评论计数。
返回值
(bool|void)
成功时为真,失败时为假,或者如果不存在带有ID的帖子。
源文件
路径:wp-includes/comment.php
<?php
...
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);
}
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_update_comment_count/