How to add featured thumbnail into import XML?

Got a working solution,

This is the post item

<item>
    <title>title1</title>
    <pubdate>2013-02-20 10:33:58</pubdate>
    <dc:creator>
    <![CDATA[ David Jennings ]]>
    </dc:creator>
    <guid ispermalink="false">http://wordpress/?p=1234</guid>
    <description>
    <title>Title</title>
    </description> 
    <content:encoded>
    <![CDATA[ABCD]]>
    </content:encoded>
    <excerpt:encoded>
    <![CDATA[ ]]>
    </excerpt:encoded>
    <wp:post_id>1234</wp:post_id>
    <wp:post_date>2013-02-20 10:33:00</wp:post_date>
    <wp:post_date_gmt>2013-02-20 10:33:00</wp:post_date_gmt>
    <wp:comment_status>open</wp:comment_status>
    <wp:comment_status>open</wp:comment_status>
    <wp:ping_status>open</wp:ping_status>
    <wp:post_name>title1</wp:post_name>
    <wp:status>publish</wp:status>
    <wp:post_parent>0</wp:post_parent>
    <wp:menu_order>0</wp:menu_order>
    <wp:post_type>post</wp:post_type>
    <wp:post_password></wp:post_password>
    <wp:is_sticky>0</wp:is_sticky>
    <category domain="category" nicename="blog"> <![CDATA[ blog ]]> </category>
    <wp:postmeta>
    <wp:meta_key>_thumbnail_id</wp:meta_key>

    <wp:meta_value><![CDATA[888888]]></wp:meta_value>

    </wp:postmeta>
</item>

This is the attachment item

<item>
    <title>title2</title>
    <link>http://wordpress/?attachment_id=888888</link>
    <pubDate>Mon, 07 Apr 2014 07:04:24 +0000</pubDate>
    <dc:creator><![CDATA[admin]]></dc:creator>
    <guid isPermaLink="false">http://wordpress/wp-content/uploads/xx/xxx/image.jpg</guid>
    <description></description>
    <content:encoded><![CDATA[]]></content:encoded>
    <excerpt:encoded><![CDATA[]]></excerpt:encoded>

    <wp:post_id>888888</wp:post_id>

    <wp:post_date>2014-04-07 07:04:24</wp:post_date>
    <wp:post_date_gmt>2014-04-07 07:04:24</wp:post_date_gmt>
    <wp:comment_status>open</wp:comment_status>
    <wp:ping_status>open</wp:ping_status>
    <wp:post_name>title2</wp:post_name>
    <wp:status>inherit</wp:status>

    <wp:post_parent>1234</wp:post_parent>

    <wp:menu_order>0</wp:menu_order>
    <wp:post_type>attachment</wp:post_type>
    <wp:post_password></wp:post_password>
    <wp:is_sticky>0</wp:is_sticky>
    <wp:attachment_url>http://wordpress/wp-content/uploads/xx/xxx/image.jpg</wp:attachment_url>
    <wp:postmeta>
    <wp:meta_key>_wp_attached_file</wp:meta_key>
    <wp:meta_value><![CDATA[/xx/xxx/image.jpg]]></wp:meta_value>
    </wp:postmeta>
</item>
  1. Create post for both attachment and post.
  2. Add relation in both post and attachment.
  3. Import XML the related attachment should be added as featured image.

Leave a Comment