Created
June 18, 2012 10:30
-
-
Save Coopeh/2947789 to your computer and use it in GitHub Desktop.
Query WPMU Comment Count For A List Of Blogs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* DB init */ | |
global $wpdb; | |
/* Get current user details and declare variables to pull blog info */ | |
$current_user = wp_get_current_user(); | |
$user_id = $current_user->id; | |
$user_blogs = get_blogs_of_user($user_id); | |
/* Go through the list of blogs and create a list element for each */ | |
foreach ($user_blogs AS $user_blog) { | |
/* Get the blog id for the current loop point */ | |
$blog_comment_id = $user_blog->userblog_id; | |
/* MD5 hash the blog_id for use with Multi-DB, remove the last 30 characters - we only need the first 2! */ | |
$db_id = substr(md5($blog_comment_id), 0, -30); | |
/* Create the SQL statement to pull the current loop point's blog pending comments and store it as $request */ | |
$sql = "SELECT COUNT(*) FROM db-prefix_{$db_id}.wp-prefix_{$blog_comment_id}_comments WHERE comment_approved = '0'"; | |
$request = $wpdb->get_var( $wpdb->prepare( $sql ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment