{"id":79,"date":"2009-06-13T15:55:01","date_gmt":"2009-06-13T21:55:01","guid":{"rendered":"http:\/\/rrbits.com\/epb\/?p=79"},"modified":"2011-02-06T17:40:00","modified_gmt":"2011-02-06T23:40:00","slug":"easily-import-sitewide-comments-wpmu","status":"publish","type":"post","link":"https:\/\/rrbits.com\/epb\/2009\/06\/13\/easily-import-sitewide-comments-wpmu\/","title":{"rendered":"Easily import sitewide comments &#8211; WPMU"},"content":{"rendered":"<p>One of my work responsibilities is the administration and development of a WordPress MU installation, <a href=\"http:\/\/pugetsoundblogs.com\/\">Puget Sound Blogs<\/a>.  Someone suggested adding a feed of the most recent comments onto the front page, but obviously this isn&#8217;t terribly easy to do with WPMU, unless you have the sitewide comments plugin. <a href=\"http:\/\/wpmudev.org\/project\/Sitewide-recent-comments\">http:\/\/wpmudev.org\/project\/Sitewide-recent-comments<\/a><\/p>\n<p>Now the problem with this plugin becomes: What do I do to import my old comments.  It&#8217;s fairly easy to simply export and re-import the comments, but I found this to be rather time consuming.  So I wrote this script to do it all for me.  Keep in mind that you&#8217;ll need to change which tables you use if they are different and whatnot, but it sure saved me a lot of time anyway.<\/p>\n<p><!--more--><\/p>\n<p><code><\/p>\n<pre>mysql_connect('HOST', 'USER', 'PASS') \r\n  or die('Could not connect to DB');\r\nmysql_select_db('DB') or die('No DB!');\r\n$blogids = mysql_query(\"SELECT blog_id \r\n  FROM wp_blogs WHERE `deleted` != 1\");\r\n\r\n\r\n\r\nwhile($row = mysql_fetch_assoc($blogids))\r\n{\r\n$id = $row['blog_id'];\r\n\r\n$q1 = \"DELETE FROM `sitewide_comments` WHERE blog_id = '{$id}'\";\r\n\r\n$q2 = \"INSERT INTO `sitewide_comments` SELECT NULL as `site_cid`,\r\n'{$id}' as `blog_id`, \r\n`comment_ID`, `comment_post_ID`, \r\n`comment_author`, `comment_author_email`, \r\n`comment_author_url`, `comment_author_IP`,\r\n`comment_date`, `comment_date_gmt`, \r\n`comment_content`, `comment_karma`,\r\n`comment_approved`, `comment_agent`,\r\n `comment_type`, `comment_parent`, \r\n`user_id` FROM wp_{$id}_comments;\";\r\n\r\necho \"Syncing $id...<br \/>\";\r\nmysql_query($q1);\r\nmysql_query($q2);\r\n\r\n}\r\necho 'done...';<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of my work responsibilities is the administration and development of a WordPress MU installation, Puget Sound Blogs. Someone suggested adding a feed of the most recent comments onto the front page, but obviously this isn&#8217;t terribly easy to do with WPMU, unless you have the sitewide comments plugin. http:\/\/wpmudev.org\/project\/Sitewide-recent-comments Now the problem with this&#8230;  <a class=\"excerpt-read-more\" href=\"https:\/\/rrbits.com\/epb\/2009\/06\/13\/easily-import-sitewide-comments-wpmu\/\" title=\"ReadEasily import sitewide comments &#8211; WPMU\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":6,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":287,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/79\/revisions\/287"}],"wp:attachment":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}