wp_update_comment_count

函式
wp_update_comment_count ( $post_id, $do_deferred = false )
引數
  • (int|null) $post_id Post ID.
    Required:
  • (bool) $do_deferred Optional. Whether to process previously deferred post comment counts. Default false.
    Required:
    Default: false
返回值
  • (bool|void) True on success, false on failure or if post with ID does not exist.
相關
  • wp_update_comment_count_now()
定義位置
相關方法
wp_update_comment_count_nowwp_update_commentwp_update_term_countwp_defer_comment_countingwp_update_network_counts
引入
2.1.0
棄用
-

wp_update_comment_count是WordPress中的一個函式,用於更新一個特定文章或一組文章的評論數: 該函式檢索每個文章的批准的評論數,然後用這個資訊更新儲存在資料庫中的postmeta。這使得WordPress能夠跟蹤每個文章的評論數量,並顯示在文章編輯介面和WordPress管理的其他區域。

更新文章的評論數。

當$do_deferred為false(預設為false),並且評論已經被設定為deferred,文章_id將被新增到一個佇列中,該佇列將在稍後的日期被更新,每個文章ID只更新一次。

如果評論沒有被設定為推遲,那麼文章將被更新: 當$do_deferred被設定為”true”時,那麼所有以前被推遲的文章ID將和當前的$post_id一起被更新。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
}
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 ); } }
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 );
	}

}

常見問題

FAQs
檢視更多 >