返回介绍

wp_update_comment_count()

发布于 2017-09-11 13:03:15 字数 2652 浏览 893 评论 0 收藏 0

wp_update_comment_count( int|null $post_id,  bool $do_deferred = false )

Updates the comment count for post(s).


description

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.


参数

$post_id

(int|null) (Required) Post ID.

$do_deferred

(bool) (Optional) Whether to process previously deferred post comment counts.

Default value: false


返回值

(bool|void) True on success, false on failure or if post with ID does not exist.


源代码

File: wp-includes/comment.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);
	}

}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/comment.php: wp_update_comment_count_now()
  • wp-includes/comment.php: wp_defer_comment_counting()

Used By

  • wp-includes/comment.php: wp_set_comment_status()
  • wp-includes/comment.php: wp_update_comment()
  • wp-includes/comment.php: wp_defer_comment_counting()
  • wp-includes/comment.php: wp_insert_comment()
  • wp-includes/comment.php: wp_delete_comment()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文