Get the total post count across all your WPMU blogs

August 28, 2010 – 4:50 pm |

Just drop this code into a script in your blog’s root directory:

  1. <?php
  2. require( dirname(__FILE__) . '/wp-load.php' );
  3. global $wpdb;
  4. $res = $wpdb->get_results('select blog_id from wp_blogs', ARRAY_A);
  5. $total = 0;
  6. foreach ($res as $result) {
  7.    $wpdb->set_blog_id($result['blog_id']);
  8.    $val = (int)$wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s",time()) . "'");
  9.    $total += $val;
  10. }
  11. echo $total;
  12. ?>

What it does is look into your database for all of the blogs that you have, then grabs the post count from each of them. Finally, it will echo out the total number of blog posts that your WordPress Mu site has published.

If you would like this feature as an administrator widget, you can download the plugin it at the Spotted Koi WordPress Mu All Blogs Post Count page.

pixel Get the total post count across all your WPMU blogs

Tagged: , , , , , , , ,