5

This is a sample item I am trying to insert into WordPress as post.

<item>
    <title>XXXXXX</title>
    <link>xxxx/xxxxx</link>
    <pubDate>2012-05-23 19:31:00</pubDate>
    <dc:creator><![CDATA[admin]]></dc:creator>
    <guid isPermaLink="false">http://wordpress/?p=xxxx</guid>
    <description></description>
    <content:encoded><![CDATA[Sample]]></content:encoded>
    <excerpt:encoded><![CDATA[]]></excerpt:encoded>
    <wp:post_id>27505</wp:post_id>
    <wp:post_date>2014-04-05 10:01:11</wp:post_date>
    <wp:post_date_gmt>2014-04-05 10:01:11</wp:post_date_gmt>
    <wp:comment_status>open</wp:comment_status>
    <wp:ping_status>open</wp:ping_status>
    <wp:post_name>xxxxxx</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>
</item>

How to inlcude a featured image into this XML, is there a way to do that?

  • How did you create that? Have you tried exporting posts incl attachments and looking at the provided XML? – kaiser Apr 7 '14 at 6:51
  • Its the other way around. You can export the media in a separate xml file, and the media is attached to the post, not the post to the image. – passatgt Apr 7 '14 at 10:15
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.