wp_update_comment_count()
wp_update_comment_count( int|null $post_id, bool $do_de…
wp_update_comment_count( int|null $post_id, bool $do_deferred = false )
更新文章的评论计数。
Updates the comment count for post(s).
更新文章的评论计数。
Updates the comment count for post(s).
目录锚点:#说明#参数#源码
说明(Description)
当$do_deferred为false(默认为)并且评论被设置为延迟时,post_id将被添加到队列中,队列将在以后更新,并且每个post id只更新一次。如果评论没有被设置为延迟,则帖子将被更新。当$do_deferred设置为true时,所有以前延迟的post id将与当前的$post_id一起更新。另请参阅wp_update_comment_count_now():了解导致错误返回值的原因
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $post_id | (int | null) | 职位ID。 |
| $do_deferred | (bool) | 是否处理先前延迟的发表评论计数。 |
源码(Source)
/**
* Updates the comment count for post(s).
*
* 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.
*
* @since 2.1.0
* @see wp_update_comment_count_now() For what could cause a false return value
*
* @staticvar array $_deferred
*
* @param int $post_id Post ID
* @param bool $do_deferred Whether to process previously deferred post comment counts
* @return bool|void True on success, false on failure
*/
function wp_update_comment_count($post_id, $do_deferred=false) {
static $_deferred = array();
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);
}
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.1.0 | wp-includes/comment.php | 10 | 3 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!