{"id":4429,"date":"2010-03-18T15:37:45","date_gmt":"2010-03-18T22:37:45","guid":{"rendered":"http:\/\/www.shibashake.com\/wordpress-theme\/?p=4429"},"modified":"2013-01-16T20:58:39","modified_gmt":"2013-01-17T04:58:39","slug":"wordpress-xml-import-format-comments","status":"publish","type":"post","link":"https:\/\/shibashake.com\/wp\/wordpress-xml-import-format-comments","title":{"rendered":"WordPress XML Import Format &#8211; Comments"},"content":{"rendered":"<p>In this article we consider how to write out comments data in the  WordPress XML import format.<\/p>\n<p>Once you do this, you can easily import  the generated XML file into WordPress by using the <strong>Import<\/strong> functionality within your WordPress dashboard.<\/p>\n<p>We assume that  you already have the <a href=\"http:\/\/shibashake.com\/wordpress-theme\/display-wordpress-comments-in-a-static-web-page\">comment  data extracted in a PHP script elsewhere<\/a>.<\/p>\n<p>The first thing  that goes into a WordPress XML comments file is the XML file header.<\/p>\n<div class=\"alignspace\"><\/div>\n<h2>WordPress Comments XML Header<\/h2>\n<p><pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;br \/&gt;\n$xml = &lt;&lt;&lt;HEADER&lt;br \/&gt;\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;br \/&gt;\n&lt;!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. --&gt;&lt;br \/&gt;\n&lt;!-- It contains information about your blog&#039;s posts, comments, and categories. --&gt;&lt;br \/&gt;\n&lt;!-- You may use this file to transfer that content from one site to another. --&gt;&lt;br \/&gt;\n&lt;!-- This file is not intended to serve as a complete backup of your blog. --&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;!-- To import this information into a WordPress blog follow these steps. --&gt;&lt;br \/&gt;\n&lt;!-- 1. Log into that blog as an administrator. --&gt;&lt;br \/&gt;\n&lt;!-- 2. Go to Manage: Import in the blog&#039;s admin panels. --&gt;&lt;br \/&gt;\n&lt;!-- 3. Choose &quot;WordPress&quot; from the list. --&gt;&lt;br \/&gt;\n&lt;!-- 4. Upload this file using the form provided on that page. --&gt;&lt;br \/&gt;\n&lt;!-- 5. You will first be asked to map the authors in this export file to users --&gt;&lt;br \/&gt;\n&lt;!--    on the blog.  For each author, you may choose to map to an --&gt;&lt;br \/&gt;\n&lt;!--    existing user on the blog or to create a new user --&gt;&lt;br \/&gt;\n&lt;!-- 6. WordPress will then import each of the posts, comments, and categories --&gt;&lt;br \/&gt;\n&lt;!--    contained in this file into your blog --&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;!-- generator=&quot;WordPress\/MU&quot; created=&quot;2008-11-17 22:40&quot;--&gt;&lt;br \/&gt;\n&lt;rss version=&quot;2.0&quot;&lt;br \/&gt;\n\txmlns:content=&quot;http:\/\/purl.org\/rss\/1.0\/modules\/content\/&quot;&lt;br \/&gt;\n\txmlns:wfw=&quot;http:\/\/wellformedweb.org\/CommentAPI\/&quot;&lt;br \/&gt;\n\txmlns:dc=&quot;http:\/\/purl.org\/dc\/elements\/1.1\/&quot;&lt;br \/&gt;\n\txmlns:wp=&quot;http:\/\/wordpress.org\/export\/1.0\/&quot;&lt;br \/&gt;\n&gt;&lt;\/p&gt;\n&lt;p&gt;&lt;channel&gt;&lt;br \/&gt;\n&lt;item&gt;&lt;br \/&gt;\nHEADER;&lt;br \/&gt;\n<\/pre>\n<\/p>\n<p><strong>Note<\/strong> &#8211; because there are multiple lines of text, we  simplify the writing of the header by using the <a href=\"http:\/\/us.php.net\/manual\/en\/language.types.string.php#language.types.string.syntax.heredoc\">heredoc  PHP string syntax<\/a>.<\/p>\n<p>After writing the header, you want to  write in the <strong>TITLE<\/strong> of the WordPress page used to store  your comments. If the title used does not currently exist within your WordPress blog, a  new page will be automatically created when you import the XML file into  WordPress.<\/p>\n<div class=\"alignspace\"><\/div>\n<h2>WordPress Page Title<\/h2>\n<p><pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;br \/&gt;\n$xml .= &quot;\\n&lt;title&gt;&quot; . $title . &quot;&lt;\/title&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;$xml .= &quot;&lt;wp:comment_status&gt;open&lt;\/wp:comment_status&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;wp:post_type&gt;page&lt;\/wp:post_type&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;wp:status&gt;private&lt;\/wp:status&gt;\\n&quot;;&lt;br \/&gt;\n<\/pre>\n<\/p>\n<p>Here,  we are saving the comments into a WordPress <strong>page<\/strong>, and  setting that page to be <strong>private<\/strong>. You can make the  WordPress page public later on if you so desire.<\/p>\n<p>Now, we are ready  to write out each of our WordPress comments. The same syntax must be  used in writing out each comment. We assume that &#8211;<\/p>\n<ol>\n<li><strong>$status<\/strong> contains the status of the comment (Approved or something else).<\/li>\n<li><strong>$author<\/strong> contains the name of the comment author.<\/li>\n<li><strong>$link<\/strong> contains the website of the comment author.<\/li>\n<li><strong>$IP<\/strong> contains the ip address of the comment author.<\/li>\n<li><strong>$date<\/strong> contains the date when the comment was first posted.<\/li>\n<li><strong>$comment<\/strong> contains the text of the comment.<\/li>\n<\/ol>\n<div class=\"alignspace\"><\/div>\n<h2>WordPress Comment  Format<\/h2>\n<p><pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;br \/&gt;\n$xml .= &quot;&lt;wp:comment&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;$xml .= &quot;&lt;wp:comment_author&gt;&lt;![CDATA[&quot; . $author . &quot;]]&gt;&lt;\/wp:comment_author&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;$xml .= &quot;&lt;wp:comment_author_email&gt;&quot; . $author . &quot;@hubpages.com&lt;\/wp:comment_author_email&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;if ($link == null)&lt;br \/&gt;\n\t$xml .= &quot;&lt;wp:comment_author_url&gt;&lt;\/wp:comment_author_url&gt;\\n&quot;;&lt;br \/&gt;\nelse&lt;br \/&gt;\n\t$xml .= &quot;&lt;wp:comment_author_url&gt;http:\/\/www.hubpages.com&quot; . $link . &quot;&lt;\/wp:comment_author_url&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;$xml .= &quot;&lt;wp:comment_author_IP&gt;&quot; . $IP . &quot;&lt;\/wp:comment_author_IP&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;wp:comment_date&gt;&quot; . $date . &quot;&lt;\/wp:comment_date&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;wp:comment_date_gmt&gt;&quot; . get_gmt_from_date($date) . &quot;&lt;\/wp:comment_date_gmt&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;wp:comment_content&gt;&lt;![CDATA[&quot; . $comment . &quot;]]&gt;&lt;\/wp:comment_content&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;if ($status == &quot;Approved&quot;)&lt;br \/&gt;\n\t$xml .= &quot;&lt;wp:comment_approved&gt;1&lt;\/wp:comment_approved&gt;\\n&quot;;&lt;br \/&gt;\nelse&lt;br \/&gt;\n\t$xml .= &quot;&lt;wp:comment_approved&gt;0&lt;\/wp:comment_approved&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;$xml .= &quot;&lt;wp:comment_type&gt;&lt;\/wp:comment_type&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;wp:comment_parent&gt;0&lt;\/wp:comment_parent&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;wp:comment_user_id&gt;0&lt;\/wp:comment_user_id&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;$xml .= &quot;&lt;\/wp:comment&gt;\\n&quot;;&lt;br \/&gt;\n<\/pre>\n<\/p>\n<p>The <strong>CDATA<\/strong> tags are used in lines 3 and 15 so that the contents will only be  interpreted as text and not as XML markup. This is important because  certain user names and comment content may contain HTML markup tags such  as paragraph tags (&lt;p&gt;,&lt;\/p&gt;). You want to transfer these  tags as is into WordPress so that the comments that show up in WordPress  will retain those formatting options.<\/p>\n<p>If you do not use the <strong>CDATA<\/strong> tags, WordPress may try to interpret those tags as part of the XML file  it is parsing and run into errors during the import process.<\/p>\n<p>After  writing all your comments, close the WordPress XML file with the  following footer.<\/p>\n<div class=\"alignspace\"><\/div>\n<h2>WordPress XML Footer<\/h2>\n<p><pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;br \/&gt;\n$xml .= &quot;&lt;\/item&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;\/channel&gt;\\n&quot;;&lt;br \/&gt;\n$xml .= &quot;&lt;\/rss&gt;\\n&quot;;&lt;\/p&gt;\n&lt;p&gt;echo $xml;&lt;br \/&gt;\n<\/pre>\n<\/p>\n<p>Echoing the results will make it appear on your web browser.  Alternatively, you can return the results to the calling process.<\/p>\n<p>If  you are sending the results to your web browser, you may save it by  using the <strong>Save As<\/strong> or <strong>Save Page As<\/strong> option in your web browser.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we consider how to write out comments data in the WordPress XML import format. Once you do this, you can easily import the generated XML file into WordPress by using the Import functionality within your WordPress dashboard. We assume that you already have the comment data extracted in a PHP script elsewhere. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3987,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":""},"categories":[139],"tags":[161,162,521,522,525,523,524,526,573],"_links":{"self":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts\/4429"}],"collection":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/comments?post=4429"}],"version-history":[{"count":14,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts\/4429\/revisions"}],"predecessor-version":[{"id":10734,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts\/4429\/revisions\/10734"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/media\/3987"}],"wp:attachment":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/media?parent=4429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/categories?post=4429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/tags?post=4429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}