wp cache get

Solutions on MaxInterview for wp cache get by the best coders in the world

showing results for - "wp cache get"
Fabio
27 Jan 2021
1function prefix_get_post_count( $post_status = 'publish' ) {
2    $cache_key = 'prefix_post_count_'. $post_status;
3    $_posts = wp_cache_get( $cache_key );
4    if ( false === $_posts ) {
5        $_posts = $wpdb->get_var(
6                    $wpdb->prepare(
7                        "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = %s",
8                        $post_status
9                    ));
10  
11        wp_cache_set( $cache_key, $_posts );
12    }
13  
14    return $_posts;
15}
16