wp_update_comment_count()更新评论的总数

目录

描述

译文

在数据库中插入评论。

有效的$commetdata关键字名称包括 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_parent', 'comment_approved', 及'user_id'。

原文

Updates the comment count for post(s).

When $do_deferred is false (is by default) and the comments have been set to be deferred, $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.

wp_update_comment_count() 描述

用法

<?php wp_update_comment_count$post_id$do_deferred ?>

wp_update_comment_count() 用法

参数

$post_id

(integer) (必填) Post ID

默认值: None

$do_deferred

(boolean) (可选) Whether to process previously deferred post comment counts

默认值: false

wp_update_comment_count() 参数

返回值

(boolean) 

True on success, false on failure

wp_update_comment_count() 返回值

注意

wp_update_comment_count() 注意

历史

添加于 版本: 2.1.0

wp_update_comment_count() 历史

源文件

wp_update_comment_count() 函数的代码位于 wp-includes/comment.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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);
	}

}

wp_update_comment_count() 源文件

相关