Importing from MT to WordPress

March 29, 2006  ·  Category: Web Development

This week I spent several hours figuring out how to import all my entries from MoveableType to WordPress.

It turns out the task is non-trivial when you’re converting to WordPress 2.0 or higher (highly recommended) and you want to preserve the numeric permalinks of your posts.

If you want to keep your old permalinks alive for search engine purposes, and you’ve been using MT’s numeric filenames, then it’s crucial that you preserve the numbering assigned to your old entries.

If you conduct an ordinary import, however, any of the posts you had deleted in MT (e.g., test posts or any posts you decided to take down) will not get counted during WP’s import, causing the numeric IDs of your new posts to not match up with the old ones.

I was able to piece together a solution that worked, however. Below are my instructions.

1. Bone up on the general topic by reading WordPress’s own documentation on importing from MT to WordPress.

2. Edit MT’s export script to include post numbers. I don’t know the first thing about perl, but fortunately Dr. Bacchus provided some crucial guidance on this:

The module that handles MT exports is at lib/MT/App/CMS.pm. In sub export you’ll find a blob of text that starts with $tmpl->text(< <'TEXT'); and defines the template with which stuff will be exported. To that blob, add a new field:

ID: <$MTEntryID$>

Placement doesn’t matter. Save the file and upload it into your old MT installation.

3. Export your entries from MoveableType. Save the exported text file to your hard drive for later use. You might want to peek at the file in a text editor, to confirm that the headers for your posts include the numeric ID for that post.

4. Update WordPress’s script for importing entries. Find the file mt.php inside the folder /wp-admin/import, and rename the file to something like mtORIG.php (for backup purposes).

Then replace the file with this one. In the new version of this file, I’ve altered the function that updates the database, to include the post number when it does the update. (For esoteric reasons, this is not a trivial modification in WordPress v.2. They’re no longer using conventional SQL queries, for one thing.)

NOTE: I am not an experienced WordPress programmer, and I can’t make any guarantees about the fitness of my patch. If anyone with more experience sees problems with my script, please send them along and I’ll update my files accordingly. That said, the script worked like a charm for me — and for another person in the support forums who was having a similar problem.

5. Import your entries into WordPress. Once you’ve uploaded the revised import script into your WordPress installation, you should be able to import just like you normally would, inside the WordPress admin section: Click on the “Import” tab, choose “MoveableType,” and follow the instructions.

BONUS: There’s one other challenge when preserving your numeric permalinks, and that’s padding the zeroes in front of the post ID in the URL. Fortunately Kafkaesqui provides the solution: Edit the template-functions-links.php file (inside the /wp-includes folder). Look for the $rewritereplace array, and in it change:

$post->ID,

to:

zeroise($post->ID, 6),

That uses the WP function zeroise() to force the ID to 6 places by inserting zeros at left when it’s less than 6 digits.

Hope these instructions are helpful. I am available to answer questions on a limited basis. Please post your questions in the comments, below, so that others can benefit from the discussion.

By Joshua Zader  ·  Trackback URL  ·  Link
 
16 Responses to “Importing from MT to WordPress”
  • Thanks for these steps! It worked for me perfectly!

    Apr 3, 2006 at 10:42 am  ·  Permalink
  • [...] The problem was more complex as I deleted and changed some of my posts (to make them more relavant to the current blog) as I migrated them over - which means I cannot use Dr Bacchus scripts or Joshua Zader’s solution. [...]

    Apr 9, 2006 at 12:15 am  ·  Permalink
  • From Jaymis

    This plugin seems to do some kind of code filtering which is causing rather strange things to happen for me. I’ve done a search and replace on my MT plaintext export file so I can use images with the Gallery2 integration WPG@. This means my image links look like this:

    storiespre2k6/soundframes.jpg

    However after importing with this script they look like this:

    storiespre2k6/soundframes.jpg

    For some reason the import eats the wpg2 tags and the div class.

    I’ve successfully imported this stuff using Kathy’s Numeric Import Script - but because it’s based on WP1.5 it requires quite a lot of work to get everything happy after import. All comments need to be moderated and approved to update the post comment counts etc.

    So, it looks like your script would be a much better option, but for some reason it doesn’t seem to be working. It does the import beautifully, but this filtering breaks most of the posts, and the numeric IDs don’t seem to be correct.

    I may have done something strange so I’m going to give this another try, but at the moment it’s a litany of badness :)

    Jaymis

    Apr 9, 2006 at 9:37 am  ·  Permalink
  • Jaymis,

    I saw your follow-up post (with the code that got eaten, above) but I had to delete because it broke my page; still not sure why it happened, but it was easiest to just remove it.

    I’m sorry to hear my script didn’t work for you. I don’t have any experience with the Gallery2 integration code you’re using, so unfortunately I don’t have any ideas about how to fix it.

    My hunch is that it’s not my modifications (which were mostly minor tweaks to a large chunk of their code that defines one of their functions), but rather something in how the new version of WordPress is filtering your imports.

    But I dunno. Hope you’re able to figure it out without too much heartache.

    Joshua

    Apr 9, 2006 at 12:25 pm  ·  Permalink
  • From Seb

    Hmm, maybe I’m crazy, but my version of MT (3.2)’s CMS.pm has a “sub export” section but no “blob of text that starts with $tmpl->text.” What version of MT were you using? (I do see the section you indicate in the CMS.pm version that came with 2.661.)

    Answer from Joshua: I don’t know what version I was using, or what to do with a different version of MT.  Sorry.

    Apr 19, 2006 at 1:41 pm  ·  Permalink
  • From Seb

    Joshua: thanks. Looks like, at least for purposes of exporting posts (forget templates and so on,) importing a 3.2 DB into a 2.6 install works well enough.

    Apr 21, 2006 at 3:39 pm  ·  Permalink
  • [WordPress]IDを維持したままMovable Type 3.2からWordPress2.0.2へ移行する

    Importing from MT 3.2 to WP 2.0.2 やってみたので忘れないうちにメモ。
    MTで使っていたIDをWPでそのまま使う、Movable TypeからWordPressの移行方法については、Mudita JournalさんのImporting from MT to WordPress...

    May 17, 2006 at 2:56 am  ·  Permalink
  • From Albert

    I migrated from Movabletype 3.31 to WordPress 2.03. Everything worked as described except that the code that has to be updated in the MT export script is now in lib/MT/ImportExport.pm (~line 529) not lib/MT/App/CMS.pm.

    Jul 15, 2006 at 7:09 pm  ·  Permalink
  • [...] I don’t know whether I could have had such features with a more modern version of Movable Type, but it certainly seemed to me that WordPress has more mindshare, plus it’s open source. And it is supported by my ISP. So, I moved from Movable Type 2.64 to WordPress 2.0.2. I followed these fantastic directions. and, for importing my 350+ entries with correct permalinks, I followed these directions. [...]

    Aug 8, 2006 at 9:58 am  ·  Permalink
  • Joshua

    Thanks for these very helpful tips. If others are, like me, exporting from 3.2 then note you’ll want to make the same change as at 2. above, but in

    lib/MT/ImportExport.pm

    and the phrase you’ll want it

    ID:

    Worked for me, anyway.

    Feb 24, 2007 at 11:13 am  ·  Permalink
  • Hi,

    I’ve recently adapted your solution to add MT’s BLOG_ID as a category to WP and thus allow the preservation and handling of previous multiblogs as WP categories.

    To do this, you would have to add an additional BLOG_ID in step 2, like

    BLOG_ID:

    and then an additional category importer step in the modified WP MT import script. I put this just below the catgory import case:

    case ‘BLOG_ID’ :
    if (! empty ($value) )
    $post_categories[] = $wpdb->escape($value);
    break;

    Unfortunately, WP can’t handle primary categories without a plugin, but there is one - top categories.

    If I’d known this before I imported the posts, I’d have installed it prior to importing the posts and adapted the script even further so the the MT_PRIMARY_CATEGORY value would have been preserved.

    Apr 10, 2007 at 9:23 pm  ·  Permalink
  • [...] In order to preserve links from other sites to my old Movable Type entries, I needed to redirect permalinks for the old entries to point to the new entries. A method for doing this for Wordpress 2.2 is documented here at the muditajounal. I took a shortcut from this solution because I had a relatively small number of entries. I created a .htaccess file in my Movable Type blog directory and added a RewriteRule for each entry like this: RewriteRule philosophers_ca.html /home/user/public_html/wp/index.php?p=41 [...]

    May 18, 2007 at 2:10 pm  ·  Permalink
  • From Adam

    I think the file to alter in the Bonus section of Step 5 has changed to wp-includes/link-template.php

    Jun 8, 2007 at 10:40 am  ·  Permalink
  • ..thanks a lot for the useful post!

    Feb 24, 2008 at 10:26 am  ·  Permalink
  • I tried your fix (replacing the mt import file with your version) but it did not work. The weird problem I am having is that all of the comments import correctly, and I even get the “Have Fun” message at the bottom of the list of posts, but the posts do not show up! However, when I look at the comments and click on a post name, the post appears as it would normally. I don’t get it.

    I have tried reinstalling everything but to no avail. And when I re-import, I get a list of the posts with a notation at the end of each name that it “already exists.”

    Weird, huh!

    Any suggestions?

    Thanks.

    Mar 5, 2008 at 2:42 pm  ·  Permalink
  • [...] migration was not especially difficult, but I did have to follow these directions to make MT print the EntryIDs in the export file, and to make WP read and use them when importing. [...]

    Mar 21, 2008 at 12:55 pm  ·  Permalink

Leave a Comment

Name required
E-mail required, won't be published
Web site
Spam protection: Sum of 1 + 4 ?