_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()的缓存密钥。

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

(工作日 10:00 - 18:30 为您服务)

2025-12-05 18:32:58

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: