update_comment_cache

函式
update_comment_cache ( $comments, $update_meta_cache = true )
引數
  • (WP_Comment[]) $comments Array of comment objects
    Required:
  • (bool) $update_meta_cache Whether to update commentmeta cache. Default true.
    Required:
    Default: true
定義位置
相關方法
update_meta_cacheupdate_postmeta_cacheupdate_termmeta_cacheupdate_comment_metaupdate_post_cache
引入
2.3.0
棄用
-

update_comment_cache: 這個函式更新當前站點的評論資料快取。每當一個評論被建立、更新或刪除時,它就被呼叫。

更新給定評論的快取。

將把$comments中的評論新增到快取中。如果評論ID已經存在於評論快取中,那麼它將不會被更新。評論被新增到快取中,使用評論組,關鍵是使用評論的ID。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function update_comment_cache( $comments, $update_meta_cache = true ) {
$data = array();
foreach ( (array) $comments as $comment ) {
$data[ $comment->comment_ID ] = $comment;
}
wp_cache_add_multiple( $data, 'comment' );
if ( $update_meta_cache ) {
// Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
$comment_ids = array();
foreach ( $comments as $comment ) {
$comment_ids[] = $comment->comment_ID;
}
update_meta_cache( 'comment', $comment_ids );
}
}
function update_comment_cache( $comments, $update_meta_cache = true ) { $data = array(); foreach ( (array) $comments as $comment ) { $data[ $comment->comment_ID ] = $comment; } wp_cache_add_multiple( $data, 'comment' ); if ( $update_meta_cache ) { // Avoid `wp_list_pluck()` in case `$comments` is passed by reference. $comment_ids = array(); foreach ( $comments as $comment ) { $comment_ids[] = $comment->comment_ID; } update_meta_cache( 'comment', $comment_ids ); } }
function update_comment_cache( $comments, $update_meta_cache = true ) {
	$data = array();
	foreach ( (array) $comments as $comment ) {
		$data[ $comment->comment_ID ] = $comment;
	}
	wp_cache_add_multiple( $data, 'comment' );

	if ( $update_meta_cache ) {
		// Avoid `wp_list_pluck()` in case `$comments` is passed by reference.
		$comment_ids = array();
		foreach ( $comments as $comment ) {
			$comment_ids[] = $comment->comment_ID;
		}
		update_meta_cache( 'comment', $comment_ids );
	}
}

常見問題

FAQs
檢視更多 >