_count_posts_cache_key

Return the cache key for wp_count_posts() based on the passed arguments.

Description

(string) _count_posts_cache_key( (string) $type = 'post', (string) $perm = '' ); 

Returns (string)

The cache key.

Parameters (2)

0. $type — Optional. (string) => 'post'
Post type to retrieve count Default post..
1. $perm — Optional. (string) => ''
readable or empty. Default empty.

Usage

  1. if ( !function_exists( '_count_posts_cache_key' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. Post type to retrieve count Default 'post'. 
  5. $type = 'post'; 
  6.  
  7. // Optional. 'readable' or empty. Default empty. 
  8. $perm = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _count_posts_cache_key($type, $perm); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function _count_posts_cache_key( $type = 'post', $perm = '' ) { 
  2. $cache_key = 'posts-' . $type; 
  3. if ( 'readable' == $perm && is_user_logged_in() ) { 
  4. $post_type_object = get_post_type_object( $type ); 
  5. if ( $post_type_object && ! current_user_can( $post_type_object->cap->read_private_posts ) ) { 
  6. $cache_key .= '_' . $perm . '_' . get_current_user_id(); 
  7. return $cache_key;