update_post_cache

函式
update_post_cache ( $posts )
引數
  • (WP_Post[]) $posts Array of post objects (passed by reference).
    Required:
定義位置
相關方法
update_post_cachesupdate_postmeta_cacheupdate_site_cacheupdate_meta_cacheupdate_term_cache
引入
1.5.1
棄用
-

update_post_cache: 這個函式更新單個文章的快取。它需要一個引數:$post。$post是一個包含文章資料的物件,其快取需要被更新。

更新快取中的文章。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function update_post_cache( &$posts ) {
if ( ! $posts ) {
return;
}
$data = array();
foreach ( $posts as $post ) {
if ( empty( $post->filter ) || 'raw' !== $post->filter ) {
$post = sanitize_post( $post, 'raw' );
}
$data[ $post->ID ] = $post;
}
wp_cache_add_multiple( $data, 'posts' );
}
function update_post_cache( &$posts ) { if ( ! $posts ) { return; } $data = array(); foreach ( $posts as $post ) { if ( empty( $post->filter ) || 'raw' !== $post->filter ) { $post = sanitize_post( $post, 'raw' ); } $data[ $post->ID ] = $post; } wp_cache_add_multiple( $data, 'posts' ); }
function update_post_cache( &$posts ) {
	if ( ! $posts ) {
		return;
	}

	$data = array();
	foreach ( $posts as $post ) {
		if ( empty( $post->filter ) || 'raw' !== $post->filter ) {
			$post = sanitize_post( $post, 'raw' );
		}
		$data[ $post->ID ] = $post;
	}
	wp_cache_add_multiple( $data, 'posts' );
}

常見問題

FAQs
檢視更多 >