Export data from Expressionengine to wordpress

I was searching for a way to export data from expressionengine as wordpress format, all i found this article only http://expressionengine.com/wiki/Export_Entries/. I followed the same technique to create a rss xml data feed such that anyone can import data to his wordpress using wp import tool directly as wordpress data fromat.

So i’ve created a template group named “export”. Then i created two templates inside “export” group – 1. data.xml 2. comments.xml. Both these templates are xml type template. data.xml is the main template, comments.xml is embedded inside data.xml. Here are the code for comments.xml

<?php

global $IN;
$IN->QSTR = '{embed:the_entry_id}';

?>

{exp:comment:entries weblog="default_site" sort="asc"}

<wp:comment>
<wp:comment_id>{comment_id}</wp:comment_id>
<wp:comment_author><![CDATA[{name}]]></wp:comment_author>
<wp:comment_author_email>{url_or_email}</wp:comment_author_email>
<wp:comment_author_url>{url}</wp:comment_author_url>
<wp:comment_author_IP>{ip_address}</wp:comment_author_IP>
<wp:comment_date>{comment_date format="%Y-%m-%d %h:%i:%s"}</wp:comment_date>
<wp:comment_date_gmt>{gmt_comment_date format="%Y-%m-%d %h:%i:%s"}</wp:comment_date_gmt>
<wp:comment_content><![CDATA[{comment}]]></wp:comment_content>
<wp:comment_approved>1</wp:comment_approved>
<wp:comment_type></wp:comment_type>
<wp:comment_parent>0</wp:comment_parent>
<wp:comment_user_id>0</wp:comment_user_id>
</wp:comment>

{/exp:comment:entries}

Everything is self-explainable. This will create few xml nodes for comments for an entry, it will take the entry id first, then pull comments accordingly. Here are codes for the data.xml

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.0/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.0/"
>
<channel>
	<title>{site_name}</title>
	<link>{site_url}</link>
	<description>SITE_DESCRIPTION_HERE</description>
	<pubDate>{current_time format="{DATE_RSS}"}</pubDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<wp:wxr_version>1.0</wp:wxr_version>
	<wp:base_site_url>{homepage}</wp:base_site_url>
	<wp:base_blog_url>{site_url}</wp:base_blog_url>
	
{exp:weblog:categories style="linear" weblog="default_site"}

	<wp:category>
		<wp:category_nicename>{category_url_title}</wp:category_nicename>
		<wp:category_parent></wp:category_parent>
		<wp:cat_name><![CDATA[{category_name}]]></wp:cat_name>
	</wp:category>
	
{/exp:weblog:categories}	

{exp:weblog:entries weblog="default_site" orderby="date" sort="desc" limit="200" offset="0" rdf="off"}
		<item>
		<title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
		<link>YOUR_BLOG_URL_WITH_TRAILING_SLASH?p={entry_id}</link>
		<pubDate>{entry_date format="{DATE_RSS}"}</pubDate>
		<dc:creator><![CDATA[{author}]]></dc:creator>

				{categories}
				<category><![CDATA[{category_name}]]></category>
				<category domain="category" nicename="{category_url_title}"><![CDATA[{category_name}]]></category>
				{/categories}

		<guid isPermaLink="false">YOUR_BLOG_URL_WITH_TRAILING_SLASH?p={entry_id}</guid>
		<description></description>
		<content:encoded><![CDATA[{body}]]></content:encoded>
		<excerpt:encoded><![CDATA[{summary}]]></excerpt:encoded>
		<wp:post_id>{entry_id}</wp:post_id>
		<wp:post_date>{entry_date format="%Y-%m-%d %H:%i:%s"}</wp:post_date>
		<wp:post_date_gmt>{gmt_entry_date format="%Y-%m-%d %H:%i:%s"}</wp:post_date_gmt>
		<wp:comment_status>open</wp:comment_status>
		<wp:ping_status>open</wp:ping_status>
		<wp:post_name>{url_title}</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:postmeta>
			<wp:meta_key>extended</wp:meta_key>
			<wp:meta_value><![CDATA[{extended}]]></wp:meta_value>
		</wp:postmeta>

		{embed="export/comments.xml" the_entry_id="{entry_id}"}			
		
		</item>
{/exp:weblog:entries}	

</channel>	
</rss>

On above you have to define following things properly
SITE_DESCRIPTION_HERE – replace this with proper site description
YOUR_BLOG_URL_WITH_TRAILING_SLASH – this is the url of your wordpress site, let you can access your wordpress site by http://example.com/blog, so replace YOUR_BLOG_URL_WITH_TRAILING_SLASH on data.xml with http://example.com/blog/

Put the weblog name properly in data.xml and comments.xml. If you have a huge site(thousands of entries) with multiple weblogs, you should you limit and offset parameter in weblog loop in data.xml, because using wordpress, you may able to import 2mb file. Neither you can remove it.

So we have done. Now hit data.xml template on your url. Let you have expressionengine site on http://myee.com, so hit http://myee.com/index.php/export/data.xml, view the sourcecode – copy it. Create a xml file with the copied text. Now go to your wp admin panel, click import under tools menu, select wordpress from the list, locate your created xml file – then import it.
Done :)

About these ads

2 thoughts on “Export data from Expressionengine to wordpress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s