_count_posts_cache_key

函式
_count_posts_cache_key ( $type = 'post', $perm = '' )
Access
Private
引數
  • (string) $type Optional. Post type to retrieve count Default 'post'.
    Required:
    Default: 'post'
  • (string) $perm Optional. 'readable' or empty. Default empty.
    Required:
    Default: (empty)
返回值
  • (string) The cache key.
定義位置
相關方法
clean_post_cachewp_count_postsupdate_post_cacheupdate_post_cachesget_next_posts_page_link
引入
3.9.0
棄用
-

count_posts_cache_key: 這個函式用來生成一個用於計算文章的快取金鑰。它接受一個可選的$type引數來指定文章型別,並返回一個包含快取金鑰的字串。

根據傳遞的引數,返回wp_count_posts()的快取金鑰。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _count_posts_cache_key( $type = 'post', $perm = '' ) {
$cache_key = 'posts-' . $type;
if ( 'readable' === $perm && is_user_logged_in() ) {
$post_type_object = get_post_type_object( $type );
if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
$cache_key .= '_' . $perm . '_' . get_current_user_id();
}
}
return $cache_key;
}
function _count_posts_cache_key( $type = 'post', $perm = '' ) { $cache_key = 'posts-' . $type; if ( 'readable' === $perm && is_user_logged_in() ) { $post_type_object = get_post_type_object( $type ); if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) { $cache_key .= '_' . $perm . '_' . get_current_user_id(); } } return $cache_key; }
function _count_posts_cache_key( $type = 'post', $perm = '' ) {
	$cache_key = 'posts-' . $type;

	if ( 'readable' === $perm && is_user_logged_in() ) {
		$post_type_object = get_post_type_object( $type );

		if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
			$cache_key .= '_' . $perm . '_' . get_current_user_id();
		}
	}

	return $cache_key;
}

常見問題

FAQs
檢視更多 >