WordPress.org

Support

Support » Multisite » post count multisite

post count multisite

  • In functions.php:

    //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); ?>

    why isnt this working? it is not outputting anything!

Viewing 1 replies (of 1 total)
  • At a guess, this:

    $cached_post_count = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->posts . ' WHERE post_status = "publish" AND post_type = "post"');

    How does it know what table? You have wp_x_posts 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘post count multisite’ is closed to new replies.
Skip to toolbar