Forum Replies Created

Viewing 1 replies (of 1 total)
  • Forum: Fixing WordPress
    In reply to: Server load
    Thread Starter Pacman

    (@drunkowl)

    What if I do this? This code will work? oO

    function get_posts_count_from_last_24h($post_type ='post') {
    
        $cached = get_transient( 'np_count' );
        if ( $cached !== false )
            return $cached;
    
        global $wpdb;
    
        $numposts = $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COUNT(ID) ".
                "FROM {$wpdb->posts} ".
                "WHERE ".
                    "post_status='publish' ".
                    "AND post_type= %s ".
                    "AND post_date> %s",
                $post_type, date('Y-m-d H:i:s', strtotime('-24 hours'))
            )
        );
    
        set_transient( 'np_count', $numposts, 1 * HOUR_IN_SECONDS );
    
        return $numposts;
    }
Viewing 1 replies (of 1 total)