📜  wp_cache_get - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:38.524000             🧑  作者: Mango

代码示例1
function prefix_get_post_count( $post_status = 'publish' ) {
    $cache_key = 'prefix_post_count_'. $post_status;
    $_posts = wp_cache_get( $cache_key );
    if ( false === $_posts ) {
        $_posts = $wpdb->get_var(
                    $wpdb->prepare(
                        "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = %s",
                        $post_status
                    ));
  
        wp_cache_set( $cache_key, $_posts );
    }
  
    return $_posts;
}