WordPress.org

Ready to get started?Download WordPress

Forums

Post count (1 post)

  1. leisegang
    Member
    Posted 1 year ago #

    //total site post count
    function post_count() {
            global $wpdb;
            if ( false === ( $cached_post_count = get_transient( 'cached_post_count' ) ) ) {
                    // It wasn't there, so regenerate the data and save the transient
                    $cached_post_count = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->posts . ' WHERE post_status = "publish" AND post_type = "post"');
                    set_transient( 'cached_post_count', $cached_post_count, 60*60*24 );
            }
            return $cached_post_count;
    }
    
    Then display it anywhere in your theme:
    
    <?php echo get_transient(cached_post_count); ?>

    is cant get this to work. waht am i doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic