Moving from ExpressionEngine to WordPress in 64 easy steps.

I’ve had a lot of requests for a post on how I moved my ExpressionEngine blogs over to WordPress so here it, finally, is. And, no, it doesn’t really take 64 steps.

The problem with moving from EE to WordPress is that while WP has an impressive selection of importing tools for various platforms built into it, ExpressionEngine isn’t one of the supported platforms. This means we have to do it ourselves and so that’s what I set out to do. You will find in the ExpressionEngine Wiki some information on how to export to the MovableType Format, but this has a couple of limitations that made it less than ideal. For example, I used the SolSpace Tags module in ExpressionEngine and wanted to move all the tags over to WordPress, but the MT format has no facility to do that. A much betterĀ  solution would be to export to WordPress’s native WXR format which does support tags, but finding info on how the WXR format is defined (it’s an extension of XML) was more difficult than I thought it would be. It doesn’t appear anyone has sat down and specifically posted what WordPress looks for and accepts in an WXR file.

Eventually I set up a test blog in WP, put in some content that hit all the features I wanted to support, and then did an WXR export to see how the file was set up. I’m far from an expert on the WXR format, but I managed to figure out enough of it to get things to work. My method is similar to the aforementioned MT export templates except that it outputs WXR formatted data instead. You can download the templates by clicking here.

To use them you’ll want to create a new template group called “export” in ExpressionEngine. Then create two RSS templates in that group to hold the templates themselves. I called the first one “export” and the second one “comments.” It doesn’t really matter what you call the first one, but the second one must be named comments so it’ll be embedded properly. If you change the name then be sure to change it in the first template file. Both templates should be set in EE as RSS pages and you should set Allow PHP to “Yes” and “On Input” on the comments template. In the first template on the very first line is the global variable {assign_variable:master_weblog_name=”yourblogshortname”} which you should change to the short name for your blog in EE.

Once you’ve done all of that you’re almost ready to start exporting data. I use the word almost because there’s one thing that I can’t account for ahead of time and that’s the amount of data you are exporting and what RAM limits your server has. There’s also the fact that these templates do not save out to a file. Instead you have to right click on the “view” link in EE’s template listing and select “open in a new tab/window” then click on that new tab and select “show page source” which will open another new window, and then save that new window’s output to an XML file.

Doesn’t matter what you call the files (I named mine SEB1.xml, SEB2.xml, etc.), but if you try to output all of your data at once and you have a crap load of it then your browser will probably crash before you can save the file. On top of all of that, WordPress has a import size limit of 10MBs per file. In the case of SEB, at the time I made the move, I transferred some 6,500+ entries and 75,000+ comments and there was no way in hell it was all going to come out as one great big file so I ended up having to do multiple exports.

Here’s how you do that: In the first template file there’s a line that reads as follows:

{exp:weblog:entries weblog="{master_weblog_name}" dynamic_start="on" limit="9999" offset="0" sort="asc" rdf="off"}

The two key parameters are the limit and offset. The limit sets the total number of entries that’ll be included an in export and the offset tells it at what entry to start at. If you have a very small blog (couple of hundred entries with less than a dozen comments each) then you might be able to get away with a single export using those settings, but if not then here’s where you will have to experiment to find out what you can get away with and it will depend on how many entries you have as well as how many comments on those entries. There is a similar line in the comments template which limits how many comments to include that is set to 1,000 comments. None of the entries on SEB ever hit 1,000 comments so that worked just fine for me, but if you have entries with more than 1,000 comments you may need to edit that template as well. Due to memory limitations on my server I found that I could only export between 100 and 300 entries at a time before EE would abort with an out of memory error. This meant that I ended up exporting some 32 files total to get everything moved over. If I got an out of memory error then I’d go in and change the limit to a smaller number (usually decrementing by 50 each time) until I got a successful export. Once it was successful I’d go back in and change the limit back to 300 and increase the offset by however much the last export put out. Do that as many times as you need to to export all your data.

If that sounds like a pain in the ass, well, it is, but there’s still more that can go wrong. Because you’re generating an XML file your browser can be pretty fucking picky about any weird or garbled characters that might happen to be in your code. SEB was originally on MovableType and in the move from that to ExpressionEngine there were a few entries that ended up with some non-standard characters in them. Whenever an export hit one of those garbled characters it would cause an XML error and I’d have to try and figure out which entry was causing the problem, edit it in EE to fix the garbled characters, and then retry that particular export. I’d say there was about a dozen entries or so that caused me fits, but if you’ve been running on EE all along then this probably won’t be a problem for you.

Now for some good news: WordPress is impressively good at importing those WXR files. If you screw up and forget to change the offset number and end up with a duplicate file (or just one that has a handful of duplicates) WordPress will NOT create duplicate entries in your database. It’ll report those as duplicate entries and reject them. WordPress will also ask you how to handle entries written by people other than the account you are logged in as when doing the importing. You can either reassign those entries to an existing WP user or you can have WP create accounts for those users when doing the import. WordPress is also just fine with importing one file after another to build up your database back to normal.

Some other things to keep in mind with these templates: They make the assumption you’re using the default field names of {body} and {extended} for your blog entries. I also didn’t include {summary} as I never used it myself so you’ll need to add that in if you want it. The code I used for exporting Tags is not included because not everyone uses that module, but I can supply it if you want it. One other thing I should have done and didn’t think of until after I was finished was adding in code to check if the {extended} field existed and if it did to put in the WP code for a Read More link. So for SEB, all the entries where I had a body and extended section became one big posting under WP. If you’re at all comfortable with making EE templates then you should be able to look at these, see how I did things, and tweak them according to your needs.

That’s pretty much the process in a nutshell. Hopefully this isn’t too confusing. If nothing else it should give you a starting point if you want to make the transition yourself. Perhaps someone else will come up with an even better way to do it. Feel free to ask me any questions you have in the comments.