{"id":1049,"date":"2012-06-17T03:45:37","date_gmt":"2012-06-17T02:45:37","guid":{"rendered":""},"modified":"2012-06-17T03:45:37","modified_gmt":"2012-06-17T02:45:37","slug":"query-wpmu-comment-count-for-a-list-of-blogs","status":"publish","type":"post","link":"https:\/\/ed.gs\/2012\/06\/17\/query-wpmu-comment-count-for-a-list-of-blogs\/","title":{"rendered":"Query WPMU Comment Count For A List Of Blogs"},"content":{"rendered":"
Recently created a new blog list function for PrimaryBlogger to allow users to see their current blogs in a lightbox iFrame, I thought it would also be nice to have a pending comment count on the page. Here’s how I accomplished it:<\/p>\n Then we just need to put it on the page…<\/p>\n Recently created a new blog list function for PrimaryBlogger to allow users to see their current blogs in a lightbox iFrame, I thought it would also be nice to have a pending comment count on the page. get_blogs_of_user does not support comment count or much else apart from giving you basic information about the users […]<\/p>\n","protected":false},"author":2,"featured_media":3554,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[75],"tags":[129,192],"yoast_head":"\nget_blogs_of_user<\/code> does not support comment count or much else apart from giving you basic information about the users accessible blogs. I had to get creative due to us being on a Multi-DB install and
$wpdb<\/code> would not use anything from the foreach loop created for use with
get_blogs_of_user<\/code>. <\/p>\n
/* DB init */\nglobal $wpdb;\n \n/* Get current user details and declare variables to pull blog info */\n$current_user = wp_get_current_user();\n$user_id = $current_user->id;\n$user_blogs = get_blogs_of_user($user_id);\n \n/* Go through the list of blogs and create a list element for each */\nforeach ($user_blogs AS $user_blog) {\n \n/* Get the blog id for the current loop point */\n$blog_comment_id = $user_blog->userblog_id;\n \n/* MD5 hash the blog_id for use with Multi-DB, remove the last 30 characters - we only need the first 2! */\n$db_id = substr(md5($blog_comment_id), 0, -30);\n \n/* Create the SQL statement to pull the current loop point's blog pending comments and store it as $request */\n$sql = "SELECT COUNT(*) FROM db-prefix_{$db_id}.wp-prefix_{$blog_comment_id}_comments WHERE comment_approved = '0'";\n$request = $wpdb->get_var( $wpdb->prepare( $sql ) );<\/pre>\n
<a href="siteurl; ?>/wp-admin/edit-comments.php?comment_status=moderated" title=" Comments awaiting moderation" target="_blank"></a><\/pre>\n","protected":false},"excerpt":{"rendered":"