Export from WordPress

by PapaScott on 01 September 2004

Update 5 May 2005: A lot of people seem to be using this script. Since I’m not using WordPress right now, I haven’t really been maintaining it. A better alternative might be the WPexport plugin by Eric Pierce, since, unlike me, he regularly exports WordPress blogs (for students at the University of South Florida).

To paraphrase Sam Ruby, a weblog software is only as good as its export function. So inspired by Shelley, starting from a b2 export script by Bill Grady, and to celebrate the release of Movable Type 3.1, I’ve just made WordPress a hell of a lot better. I humbly present Version 0.1 of an export script for WordPress for the Movable Type import format.

A few caveats, apart from the usual it-works-for-me, your-mileage-may-vary and backup-your-data-first.

  1. It does not deal (yet) with entries with multiple categories. I don’t use multiple categories, so I don’t need this, but it could be done by adding yet another JOIN statement to the SQL and some fiddling with the output logic.
  2. There are a few settings that I’ve chosen not to read from WordPress, but instead to set explicitly in the script. If you look in the print_post function, you’ll see echo ("STATUS: Publish/n"); echo ("ALLOW COMMENTS: 2/n"); echo ("CONVERT BREAKS: markdown/n"); echo ("ALLOW PINGS: 0/n"); I.e., all posts are published, all comments are closed, all pings are allowed, and all posts are filtered with markdown. You may want to change these or comment them out to suit your needs.

  3. The post slug from WordPress is copied into the key words field. To keep your existing URLs, you’ll want to use a solution like Mark Pilgrim’s cruft-free URLs. Note also that Movable Type uses underscores in their URLs; to have MT produce dashes automatically you’ll need a plugin of some sort. Stay tuned.

  4. When importing, make sure your character set matches whatever you were using with WordPress. Both WordPress and Movable Type now use UTF-8 by default, but if you’re using something else, you’ll want to adjust MT accordingly.

  5. I’m also not yet dealing with extended entries, although that would also be easy enough to do. Everything gets thrown into the main post for now.

  6. If you search the WordPress forums, you’ll notice that inquiries about exporting to Movable Type are met with abuse and derision. Be prepared for the same if you actually use this script to export your blog to Movable Type.

I’ll be happy to update the script if anyone cares to correct any of these caveats (or anything else that I haven’t thought of). For your abuse and derision, you can see the result of the export at http://mt.papascott.de/ (temporary URL, don’t go linking to it or anything).

Matt September 1, 2004 at 07:09

… where did my linebreaks go? Ah well. Pretend there are bullets and paragraphs there. I’ll chalk it up to being tired or a glitch in the matrix. :)

Matt September 1, 2004 at 07:09

Groovy! Carthik is working on a non-lossy export using XML. MT export is great for portability (it’s a fairly widely supported format) but isn’t ideal as a WP export because it doesn’t support everything WP does. When Carthik finishes the XML version (it’s definitely going to be in 1.3) it will export (and import) custom fields, category hierarchy, post status, timezones, geo info, etc etc… basically lossless, and since it’s XML we can do the encoding right too.

Anyway, if you’re interested in cleaning up the MT script here are a few suggestions. I can try to help with things but my time is tight at the moment (hence an export not being written already!):

  • I would leverage WP functions, ie the $wpdb database class and the template tags. No need to fill in DB stuff again
  • I would break it up from One Giant Query into a bunch of iterated smaller ones. I know this isn’t traditionally the best approach but you’re less likely to run into memory limits that way (and your query is pretty heavy)
  • Again with $wpdb, use the table name variables so people who use a different prefix than wp_

Hmm, I actually had more when I started typing this but it has slipped my mind. I’ll be back later. You might consider putting this on the wiki or filing a bug so other people could also contribute to this. I believe Shelley at BB was working on something similar.

PapaScott September 1, 2004 at 08:09

They’re back now. I had experimented with the new upstream version of MarkDown, and it was eating all the line breaks.

Carthik September 1, 2004 at 11:09

I had finished work on a similar script a while ago, but then I agreed with Matt when he said that given the problems with the MT export format, we should think of a reasonable lossless and easily managed format.

My hack, based off of the same base as you hack is here:
http://blog.carthik.net/wpexportv2.phps

It just begins to use the $wpdb class. The mysql related queries in there need to be replaced with $wpdb queries, but one improvement you could use is to avoid having the user to fill in the db details.

Jim S September 1, 2004 at 15:09

one more question…

if I do use mutliple categories but don’t really care if they output correctly, since it was only a WP experiment on my testblog (I’ve never used them on MT….), will the script break if I just don’t fiddle with it and assume that it’ll export the first category?

Jim S September 1, 2004 at 15:09

um… I may sound stupid for asking this, but…

how does one go about using it?

Carthik September 1, 2004 at 16:09

You can use mine by saving the file as a .php file, uploading it to the root WP directory and accessing the page through your browser.

Jim, mine exports all the categories, so no probs there.

Shelley September 2, 2004 at 02:09

Yes, I imagine that a lossless XML export covering all that data would be great. Unfortunately, the data model is unique to Wordpress, so it would only be good to export from Wordpress to Wordpress. Which is cool, but a SQL data dump would be better for that purpose.

Now, if the Atom effort were to kick its butt to start getting all tool vendors to use the same, or similiar data model, well then Bob’s your uncle — you already got a export format.

And Jim, you just run Scott’s and save the resulting page using your browser, as MT’s work. You need to fill in the database info is all.

Carthik September 2, 2004 at 05:09

Which is cool, but a SQL data dump would be better for that purpose.
Not everybody is an SQL expert, or should need to be, to use WordPress.

Unfortunately, the data model is unique to Wordpress
Just like MT’s is.

Perhaps, like WordPress’ community, of which I am member, MT’s community has yet coders who can write a wordpress importer, just like wordpress has it’s MT importer. Does that sound preposterous? If yes, why so? :)

Note to Scott,

Please feel free to delete my comment above, if in any way you felt it does not belong there. I was trying to be helpful in whatever way I could, is all. Thank you for the effort and time you spent on making this possible. :)

PapaScott September 3, 2004 at 05:09

I’m not into deleting comments…

I like the script being something that’s independent of WordScript, and doesn’t depend on having to find wp-config.php. Now if such a export function were to be included with WordPress itself, it would be worth it to hook into the various WP functions.

While a proprietary XML export might be cool for developers, I don’t really see that users get any benefit from it. MT Import is an imperfect, uncool format, but it’s the de-facto standard and it works, not only for MT, but for pMachine, Expression Engine, Textpattern, all the b2 variants, and probably a bunch of other programs that I’ve never tried.

If you want an example of an XML export that noone knows what to do with, you need look no further than Userland.

John Gray September 4, 2004 at 23:09

This rocks. I’m having to switch from WP to MT for one of my sites (I’ll post the reasons later on my blog), and this script made my life so much easier.

Richard Evans Lee September 5, 2004 at 18:09

Many thanks. When I imported I had about a dozen comments consisting of either “AM” or “PM” but they were easily cleared away.

Casey Kelley September 6, 2004 at 08:09

Worked GREAT! Thanks alot! Now I gotta figure out if it was all worth the move to MT! :P

Stewart C. Russell September 22, 2004 at 03:09

import-mt.php seems to have problems with entries generated by WP and then subsequently reimported with your script — the entries are blank. Why would I do this? To restore post IDs from an older MT installation, of course.

Vicnan October 12, 2004 at 19:42

I get a blank screen when I access the script. I’m pretty sure that I’ve gotten all my setting right, for when I mad a mistake, an error message was shown. What could I be doing wrong?

vissu September 20, 2006 at 06:21

great effort,be little more clear so that no one will get errors while using,thank you for your good job

Morteza October 5, 2006 at 03:35

good site

Don Lapre Lover November 22, 2006 at 00:22

Thankd for the idea and plugin. I haven’t used WP that much so I am looking for new things all the time. Thanks.

Laura
Don Lapre Lover
http://www.lauraglydaband.com
laura@lauraglydaband.com

sohbet November 25, 2006 at 09:22

Please feel free to delete my comment above, if in any way you felt it does not belong there. I was trying to be helpful in whatever way I could, is all. Thank you for the effort and time you spent on making this possible.

chat November 30, 2006 at 20:47

intresting text , Thanks!

Comments on this entry are closed.

{ 6 trackbacks }

Previous post:

Next post: