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
查看更多 >