Answers for "wp_cache_get"

PHP
0

wp_cache_get

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;
}
Posted by: Guest on July-29-2020

Code answers related to "wp_cache_get"

Browse Popular Code Answers by Language