Create xml file to be used in wordpress post import

admin

Administrator
Staff member
Alright here is the thing, I have this site that <strong><em>was</em></strong> once wordpress but have been converted into <strong>70+ static pages</strong>, the admin is deleted and the whole site is static(which means every page is in index.html), I want to create a script that makes an xml so that I will just have to import it in the new wordpress install.

So far, I am able to create an XML but it <strong>only imports one post</strong>.

The data source is the URL of a page and I use jquery $get to filter only to gather the post of a given archive.

Code:
//html
&lt;input type="text" class="full_path"&gt;
&lt;input type="button" value="Get Data" class="getdata"&gt;

//script

$('.getdata').click(function(){
            $.get($('.full_path').val(), function(data) {
              post = $(data).find('div [style*="width:530px;"]');
              $('.result').html(post.html());

            });
        });//get Data

Through AJAX I send the cleaned data into a php below that creates the XML:

Code:
$file = 'newpost.xml';
$post_data = $_REQUEST['post_data'];
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new post to the file
$catStr = '';
if(isset($post_data['categories']) &amp;&amp; count($post_data['categories']) &gt; 0){
    foreach($post_data['categories'] as $category) {
        $catStr .= '&lt;category domain="category" nicename="'.$category.'"&gt;&lt;![CDATA['.$category.']]&gt;&lt;/category&gt;';
    }   
}
$tagStr = '';
if(isset($post_data['tags']) &amp;&amp; count($post_data['tags']) &gt; 0){
    //populate post_tag like the above
}
$post_name = str_replace(' ','-',$post_data["title"]);
$post_name = str_replace(array('"','/',':','.',',','[',']','“','”'),'',strtolower($post_name));

$post_date = '2011-4-0'.rand(1, 29).''.rand(1, 12).':'.rand(1, 59).':'.rand(1, 59);
$pubTime = rand(1, 12).':'.rand(1, 59).':'.rand(1, 59).' +0000';

$post = '
    &lt;item&gt;
        &lt;title&gt;'.$post_data["title"].'&lt;/title&gt;
        &lt;link&gt;'.$post_data["link"].'&lt;/link&gt;
        &lt;pubDate&gt;'.$post_data["date"].' '.$pubTime.'&lt;/pubDate&gt;
        &lt;dc:creator&gt;admin&lt;/dc:creator&gt;
        &lt;guid isPermaLink="false"&gt;http://localhost/saunders/?p=1&lt;/guid&gt;
        &lt;description&gt;&lt;/description&gt;
        &lt;content:encoded&gt;&lt;![CDATA['.$post_data["content"].']]&gt;&lt;/content:encoded&gt;
        &lt;excerpt:encoded&gt;&lt;![CDATA[]]&gt;&lt;/excerpt:encoded&gt;
        &lt;wp:post_id&gt;1&lt;/wp:post_id&gt;
        &lt;wp:post_date&gt;'.$post_date.'&lt;/wp:post_date&gt;
        &lt;wp:post_date_gmt&gt;'.$post_date.'&lt;/wp:post_date_gmt&gt;
        &lt;wp:comment_status&gt;open&lt;/wp:comment_status&gt;
        &lt;wp:ping_status&gt;open&lt;/wp:ping_status&gt;
        &lt;wp:post_name&gt;'.$post_name.'&lt;/wp:post_name&gt;
        &lt;wp:status&gt;publish&lt;/wp:status&gt;
        &lt;wp:post_parent&gt;0&lt;/wp:post_parent&gt;
        &lt;wp:menu_order&gt;0&lt;/wp:menu_order&gt;
        &lt;wp:post_type&gt;post&lt;/wp:post_type&gt;
        &lt;wp:post_password&gt;&lt;/wp:post_password&gt;
        &lt;wp:is_sticky&gt;0&lt;/wp:is_sticky&gt;
        '.$catStr.'
        '.$tagStr.'
        &lt;wp:postmeta&gt;
            &lt;wp:meta_key&gt;_edit_last&lt;/wp:meta_key&gt;
            &lt;wp:meta_value&gt;&lt;![CDATA[1]]&gt;&lt;/wp:meta_value&gt;
        &lt;/wp:postmeta&gt;
    &lt;/item&gt;
';



// Write the contents back to the file with the appended post
file_put_contents($file, $current.$post);

After being appended I add the code below to complete the xml rss tag

Code:
&lt;/channel&gt;
&lt;/rss&gt;

If I look and compare the xml file of one that is exported from a wordpress site, I see little difference. Please HELP!!

here is a sample of a generated xml:

Code:
&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;rss version="2.0"
    xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:wp="http://wordpress.org/export/1.2/"
&gt;
&lt;channel&gt;
    &lt;title&gt;lols why&lt;/title&gt;
    &lt;link&gt;http://localhost/lols&lt;/link&gt;
    &lt;description&gt;Just another WordPress site&lt;/description&gt;
    &lt;pubDate&gt;Wed, 03 Oct 2012 04:24:04 +0000&lt;/pubDate&gt;
    &lt;language&gt;en-US&lt;/language&gt;
    &lt;wp:wxr_version&gt;1.2&lt;/wp:wxr_version&gt;
    &lt;wp:base_site_url&gt;http://localhost/lols&lt;/wp:base_site_url&gt;
    &lt;wp:base_blog_url&gt;http://localhost/lols&lt;/wp:base_blog_url&gt;

    &lt;wp:author&gt;&lt;wp:author_id&gt;1&lt;/wp:author_id&gt;&lt;wp:author_login&gt;adedoy&lt;/wp:author_login&gt;&lt;wp:author_email&gt;[email protected]&lt;/wp:author_email&gt;&lt;wp:author_display_name&gt;&lt;![CDATA[adedoy]]&gt;&lt;/wp:author_display_name&gt;&lt;wp:author_first_name&gt;&lt;![CDATA[]]&gt;&lt;/wp:author_first_name&gt;&lt;wp:author_last_name&gt;&lt;![CDATA[]]&gt;&lt;/wp:author_last_name&gt;&lt;/wp:author&gt;


    &lt;generator&gt;http://wordpress.org/?v=3.4.1&lt;/generator&gt;

    &lt;item&gt;
        &lt;title&gt;Sample lift?&lt;/title&gt;
        &lt;link&gt;../../breast-lift/delaware-breast-surgery-do-i-need-a-breast-lift/&lt;/link&gt;
        &lt;pubDate&gt;Wed, 03 Oct 2012 9:29:16 +0000&lt;/pubDate&gt;
        &lt;dc:creator&gt;admin&lt;/dc:creator&gt;
        &lt;guid isPermaLink="false"&gt;http://localhost/lols/?p=1&lt;/guid&gt;
        &lt;description&gt;&lt;/description&gt;
        &lt;content:encoded&gt;&lt;![CDATA[&lt;p&gt;sample&lt;/p&gt;]]&gt;&lt;/content:encoded&gt;
        &lt;excerpt:encoded&gt;&lt;![CDATA[]]&gt;&lt;/excerpt:encoded&gt;
        &lt;wp:post_id&gt;1&lt;/wp:post_id&gt;
        &lt;wp:post_date&gt;2011-4-0132:45:4&lt;/wp:post_date&gt;
        &lt;wp:post_date_gmt&gt;2011-4-0132:45:4&lt;/wp:post_date_gmt&gt;
        &lt;wp:comment_status&gt;open&lt;/wp:comment_status&gt;
        &lt;wp:ping_status&gt;open&lt;/wp:ping_status&gt;
        &lt;wp:post_name&gt;sample-lift?&lt;/wp:post_name&gt;
        &lt;wp:status&gt;publish&lt;/wp:status&gt;
        &lt;wp:post_parent&gt;0&lt;/wp:post_parent&gt;
        &lt;wp:menu_order&gt;0&lt;/wp:menu_order&gt;
        &lt;wp:post_type&gt;post&lt;/wp:post_type&gt;
        &lt;wp:post_password&gt;&lt;/wp:post_password&gt;
        &lt;wp:is_sticky&gt;0&lt;/wp:is_sticky&gt;
        &lt;category domain="category" nicename="Sample Lift"&gt;&lt;![CDATA[Sample Lift]]&gt;&lt;/category&gt;&lt;category domain="category" nicename="Sample Procedures"&gt;&lt;![CDATA[Yeah Procedures]]&gt;&lt;/category&gt;
        &lt;category domain="post_tag" nicename="delaware"&gt;&lt;![CDATA[delaware]]&gt;&lt;/category&gt;
        &lt;wp:postmeta&gt;
            &lt;wp:meta_key&gt;_edit_last&lt;/wp:meta_key&gt;
            &lt;wp:meta_value&gt;&lt;![CDATA[1]]&gt;&lt;/wp:meta_value&gt;
        &lt;/wp:postmeta&gt;
    &lt;/item&gt;
    &lt;item&gt;
        &lt;title&gt;lalalalalala&lt;/title&gt;
        &lt;link&gt;../../administrative-tips-for-surgery/delaware-cosmetic-surgery-a-better-experience/&lt;/link&gt;
        &lt;pubDate&gt;Wed, 03 Oct 2012 3:20:43 +0000&lt;/pubDate&gt;
        &lt;dc:creator&gt;admin&lt;/dc:creator&gt;
        &lt;guid isPermaLink="false"&gt;http://localhost/lols/?p=1&lt;/guid&gt;
        &lt;description&gt;&lt;/description&gt;
        &lt;content:encoded&gt;&lt;![CDATA[
                lalalalalala
            ]]&gt;&lt;/content:encoded&gt;
        &lt;excerpt:encoded&gt;&lt;![CDATA[]]&gt;&lt;/excerpt:encoded&gt;
        &lt;wp:post_id&gt;1&lt;/wp:post_id&gt;
        &lt;wp:post_date&gt;2011-4-0124:39:30&lt;/wp:post_date&gt;
        &lt;wp:post_date_gmt&gt;2011-4-0124:39:30&lt;/wp:post_date_gmt&gt;
        &lt;wp:comment_status&gt;open&lt;/wp:comment_status&gt;
        &lt;wp:ping_status&gt;open&lt;/wp:ping_status&gt;
        &lt;wp:post_name&gt;lalalalalala&lt;/wp:post_name&gt;
        &lt;wp:status&gt;publish&lt;/wp:status&gt;
        &lt;wp:post_parent&gt;0&lt;/wp:post_parent&gt;
        &lt;wp:menu_order&gt;0&lt;/wp:menu_order&gt;
        &lt;wp:post_type&gt;post&lt;/wp:post_type&gt;
        &lt;wp:post_password&gt;&lt;/wp:post_password&gt;
        &lt;wp:is_sticky&gt;0&lt;/wp:is_sticky&gt;
        &lt;category domain="category" nicename="lalalalalala"&gt;&lt;![CDATA[lalalalalala]]&gt;&lt;/category&gt;
        &lt;category domain="post_tag" nicename="oink"&gt;&lt;![CDATA[oink]]&gt;&lt;/category&gt;
        &lt;wp:postmeta&gt;
            &lt;wp:meta_key&gt;_edit_last&lt;/wp:meta_key&gt;
            &lt;wp:meta_value&gt;&lt;![CDATA[1]]&gt;&lt;/wp:meta_value&gt;
        &lt;/wp:postmeta&gt;
    &lt;/item&gt;
&lt;/channel&gt;
&lt;/rss&gt;

Please tell me what am I missing....