Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Importing from Movable Type to WordPress

wp-alert.png
This article, written to accord with WordPress 2.0, is now obsolete. Please take caution when following its contents, as many things may have changed.

Introduction and Synopsis

So you want to see what it is about WordPress that makes it Movable Type's equal? This guide will help you with all the information you need to migrate your weblog from Movable Type (MT) or TypePad to WordPress (WP). We will use MT's exporter to export all the entries and comments in your MT blog and then import them using WP's import-mt.php importer. Finally, we will look at some issues concerning the preservation of links to articles (permalinks) after the import, and other issues that you may have. This guide will leave you feeling good, warm, and hopefully looking forward to a new life full with open source goodness. If you are a TypePad user, then read "TypePad" wherever this guide talks about "Movable Type". The process of exporting entries from a TypePad blog will be different, and you should contact the TypePad support folks if you are in doubt.

Overview

To begin with, the following are assumed:

  • You have already installed WordPress on your server, so if you have not, please do so before continuing.
  • http://example.com/wordpress/ is the url of your WordPress installation.
  • "admin" is the login you use to login as the administrator of the WordPress blog.
  • "mtuserX" is the name of author X, in the MovableType blog.

The steps involved in the migration are as follows:

  1. Exporting from Movable Type
  2. Editing the WordPress importer
  3. Importing into WordPress
  4. Tying up loose ends, if any

Exporting from MovableType

  1. Login to your MovableType blog. You will see a screen that looks like Figure 1.
  2. From the main menu, click on the "Configuration" link for the blog whose entries you want to export, as shown by the red arrow in Figure 1.
  3. That link should bring you to a page similar to that shown in Figure 2. Click the "Import/Export" button on the left menu, as shown by the red arrow in Figure 2.
  4. On the page that ensues, Click the "Export Entries from <your weblog's name>" link as shown by the red arrow in Figure 3. Don't worry, the comments are exported too.
  5. Now you should see readable text, split over several lines, in your browser. If the text is one long, running line, and if you are using any version of Internet Explorer, then you have a problem. Internet Explorer sometimes treats plaintext as html. To avoid this problem do one of the following:
  • Use a Gecko-based browser, such as Netscape, Mozilla, or FireFox. Save the page you see in your browser, with all the entries in text, as a text file with the name "import.txt", on your computer.
  • If you do not want to use another browser, then in Internet Explorer, copy all the text you see in the browser, open WordPad, or Notepad (a simple text editor), but definitely not MS Word, and paste the text in. Then save the file in the text editor with the name "import.txt".
  • If you are exporting from MovableType Version 3.0D, then the bug fix for AM/PM problem is essential.
  • WordPress uses UTF-8 as the default encoding. So if your MT blog uses ISO 8859-1 or Latin - 1 to encode posts, convert the posts to UTF-8 before importing, to ensure that all characters display properly.
    • On *nix and OSX you can use the iconv program to convert your import.txt file: $ iconv -f ISO-8859-1 -t UTF-8 import.txt > import_new.txt
    • You can also use one of many scripts available online.
    • Optionally, you could also set an Option (Option -> Reading -> Character Encoding) in WordPress to set the Charset for the WP weblog to ISO 8859-1 before importing the posts.

Editing import-mt.php

1. Open the file "import-mt.php" in your favourite text editor. You will find it in the directory "wp-admin/import/" in your WordPress installation . For this, you have to download it first.

2. On line number 2 of import-mt.php, find define('MTEXPORT', ); and change that to define('MTEXPORT', 'import.txt');

3. Save import-mt.php and upload it to the "wp-admin" directory on your server, overwriting the existing "import-mt.php".

4. Upload the "import.txt" file you had saved earlier after the export to the "wp-admin" directory on your server.

Importing Entries into WordPress

  1. Log into your WordPress installation as the user admin
  2. Visit the page http://example.com/wordpress/wp-admin/import-mt.php (Of course, please visit the corresponding page on your WordPress blog, this link is just an example).
  3. Click on the link that says "let's go!"
  4. On the next page, you will see all the authors in the Movable Type weblog, and for each of these authors, you can choose either an existing WordPress user from the dropdown list, or type a username for a new user to be created in WordPress. You can use this to "map" users on your Movable Type weblog to users in the WordPress weblog, if in case the names of the author(s) are different in your WordPress blog, and you want to change the authors' names. For example, the Movable Type user "mtuserX" might correspond to the "admin" user on your WordPress installation. If you do not wish to change the names of the MT authors, just leave the corresponding entries blank, and new WP authors will be created with the same name as the MT authors. Make the changes you desire, and when you are done, click the "Submit" button.
  5. Now you will see a number of lines informing you of the progress of the import, as it happens. When it is all over, you will be asked to "Have Fun".
  6. Go ahead, have fun - the import of posts, comments, pingbacks and trackbacks is complete!
  7. If any new authors were created in WordPress during the import process, according to your wishes, the password for those users/authors is changeme. You can use this password to log in as that user. Please change the password the first time you log in after the import, since everyone who's read this guide knows the password!

Odds and Ends

Importing a Huge Number of Posts

If you don't have administrative control of the server (root access), then Importing a Large Number of Posts has relevant links and help. This should be helpful if your import process dies before completing the import. The php installation on your webserver may have a low script timeout, or if the file is too large, your server may run out of memory. This is what's happening when you see a blank, white page, during the import, or your browser says "Done" before WordPress says "Have Fun!" after the import.

If you do have root access to the server, edit php.ini and increase the maximum memory setting. For a large import (e.g. 5MB), increase the script memory to 100MBs and restart apache. When the import is complete, restore the limit to what it was originally and restart apache again.

Preserving Permalinks

Search Engines such as Google will still link to the old Movable Type generated URLs when linking to your articles. This is true of other websites too, that may have linked to your posts or articles. It is your best interests to preserve those links, to prevent visitors following those links from seeing a "404: article not found" error page. The following steps will help you preserve the links, depending on how the permalinks were configured on your Movable Type weblog.

Using an MT Individual Entry Template for Redirection

Alex King's solution provides a Movable Type template for individual entries, which you can use to generate pages that will redirect visitors to the corresponding WordPress pages. However, this method requires that you maintain the Movable Type installation, as also the pages generated by it, which will do the redirection.

Using .htaccess for redirection

Matt's method uses the .htaccess file for redirection.

Create a Movable Type template like the following, have it output to redirect.php in your WP root directory:

<?php
require('wp-config.php');
header('Content-type: text/plain');
?>
<MTEntries lastn="999999">
Redirect Permanent /archives/<$MTEntryID$>.html http://www.example.org/archives/<$MTArchiveDate format="%Y/%m/%d"$>/
   <?php echo sanitize_title("<$MTEntryTitle$>"); ?>
</MTEntries>

If your entry IDs in MovableType are padded with zeroes (0), then change the line above to

Redirect Permanent /archives/<$MTEntryID pad="1"$>.html http://www.example.org/archives/<$MTArchiveDate format="%Y/%m/%d"$>/
   <?php echo sanitize_title("<$MTEntryTitle$>"); ?>

Also, if your used the "dirify" option, for example, when in MT, if you had:

  • Archive Type: Individual,
  • Archive File Template: <MTEntryTitle dirify="1">.php,
  • quotes in title etc,

Use:

Redirect Permanent /archives/<MTEntryTitle dirify="1">.php 
 http://www.example.com/index.php?s=<$MTEntryTitle encode_url="1"$>

or if the extension for the pages were ".html", instead of the ".php" above, use:

Redirect Permanent /archives/<$MTEntryID$>.html 
 http://www.example.com/index.php?s=<$MTEntryTitle encode_url="1"$>

Using .htaccess and mod_rewrite for redirection

Apache 1.3 and above have a module, called mod_rewrite, that allows URL to be seamlessly rewritten on the fly by the server. This can be used to preserve the previous permalinks from a MovableType installation. To use mod_rewrite, the module must be installed and the FollowSymLinks option must be enabled for your blog directory. If these two conditions are true, then it's as easy as creating a .htaccess file with the following lines in it:

RewriteEngine on
RewriteRule archives/0*(\d+).html /uri/to/blog/index.php?p=$1
RewriteRule index.rdf /uri/to/blog/index.php?feed=rdf
RewriteRule index.rss /uri/to/blog/index.php?feed=rss
RewriteRule index.xml /uri/to/blog/index.php?feed=rss2
  • Note that this will also preserve RSS and RDF feeds that may be being used by third party sites.

Preserving the Numerical Post Ids

If you are using WordPress 2.0 or newer, you will need to use Joshua Zader's solution: Mudita Journal: Importing from MT to WordPress

The information below largely pertains to older versions of WordPress.

If you want your imported posts in WordPress to have the same numerical post ids as in Movable Type, use Kathy's MT-Numeric-Id Importer. Note that this might not work very well, if you had "padded" numeric ids in Movable Type. However, a peek into the code, and a little familiarity with PHP should help you fix this, if required.

Another option is to use Dr. Bacchus' Solution for the same problem.

See also: http://scott.yang.id.au/2004/06/wordpress-migration-notes/

Forcing Wordpress to Use the Movable Type Permalink Structure

Allan Barizo provides a solution that forces Wordpress to use the same permalinks as Movable Type. However, since Movable Type does not always stick to a set number of characters in the entry_basename column, also known to WordPress users as a "slug" or %postname%," there are sometimes a few Page Not Found (404) errors. It is recommended that this method be used in conjunction with the strategies outlined above. It involves changing the permalink structure under "Options" to

/archives/%year%/%monthnum%/%postname%.html

Since the %postname% in Wordpress substitutes dashes for spaces, it may be desirable to install the Underscore Permalinks Plugin. You may wish to defer this in case the solutions below do not work.

Generally, a SQL Query must be run on the wp_posts table in the WordPress MySQL database. This is because every Movable Type installation has a different %postname% length cutoff point. (The cutoff point in Movable Type can be seen under Settings, New Entry Defaults tab, Basename Length for the value). On the contrary, WordPress displays the whole URL. Before running this SQL query, replace "15" with the number of characters in the Basename Length field for the particular MT installation. Remember, to back up your MySQL database before performing this operation.

UPDATE wp_posts SET post_name=SUBSTRING(post_name,1,15)

This query assumes that all of the posts in the database are imported from MovableType. Also note that any subsequent posts written or imported after running this query will follow the unlimited %postname% WordPress rule. In other words, this query will not have any effect on later post permalinks.

If the Movable Type blog is rather old, you may have upgraded Movable Type and changed it to use long URLs (more than 15 characters) for your entries. In this case, additional work may be needed. Let's assume that prior to September 1, 2005 your MT blog had a hard coded 15 character entry_basename limitation. You upgraded on September 1, 2005 and set the entry_basename limit to 50 characters. So an entry titled "This is a very long entry" written on August 30, 2005 had an entry_basename of "this_is_a_very" in Movable Type. (Movable Type will strip off the ending underscore.) This means that Page Not Found (404) errors when search engines provide these URLs. You may be able to fix many of these link errors by using phpMyAdmin to determine when the entry_basename size increased in your Movable Type MySQL database. Once you have determined the date then you can use SQL to fix all entries before this date to have the original 15 character limitation. Of course you don't want this change to affect those after this date. Example:

UPDATE wp_posts SET post_name=SUBSTRING(post_name,1,15)
WHERE post_date < '2005-09-01'

There will likely still be inconsistencies. Some post_name values will contain a post_name ending in an underscore. This will cause page not found errors for these URLs. This SQL will clean up these posts, reducing but likely not eliminating this problem.

UPDATE wp_posts 
SET post_name = SUBSTRING(post_name,1,(length(post_name) -1)) 
WHERE RIGHT(post_name,1) = '_'

The next step is to change all dashes in the post_name field in WordPress to underscores. This can be done with this command:

UPDATE wp_posts SET post_name=REPLACE(post_name, '-', '_')

Mark D. Hamill wrote a utility that may help show the posts where the permalink is inconsistent between Movable Type and WordPress. It was tested using Movable Type 3.3 and Wordpress 2.3. You will need to save the file with a .php extension and change some script variables to match your instance of MySQL. Of course it must be placed on your server and run from it with an appropriate URL. Once bad links are identified they can be changed using phpMyAdmin or a similar tool by carefully editing the post_name column for the appropriate rows in the wp_posts table. Rerun the utility until no link inconsistencies are found.

Importing Tags

If you created tags in your Movable Type blog and want to move them over, it is possible but tricky and possibly error prone.

First, make sure that you have all post permalinks preserved as in Movable Type using the guidance above. In order to move tags for your blog entries, there must be a way to find a Movable Type entry in WordPress and this can only be done if they have something in common. Ensuring the same permalink between Movable Type and Wordpress allows tags in Movable Type to be associated in Wordpress.

To actually move the tags, try a Movable Type tag import utility written by Mark D. Hamill. While it worked for him, it has not been extensively tested so send him feedback. It should be considered "Alphaware" so use it at your own risk and with the expectation that it might fail. Make sure you backup your database before trying to use this utility.

Read the utility's instructions carefully before running it. It was tested using Movable Type 3.3 and Wordpress 2.3 and may not work for other versions. You will need to save the file with a .php extension and change some script variables to match your MySQL database. Of course it must be placed on your server and run from it with an appropriate URL. Guidance on running the utility can be found by invoking it. When ready to actually move over the tags, add a ?run=1 to the end of the URL.

User Experiences

The following are a bunch of links to posts by users describing their MT to WP move. This might be handy to see if someone has faced the sinister problems you are facing (God Forbid!) :

  1. Carthik's notes, complete with links
  2. Dan Hersam on converting links
  3. PapaScott's Notes - a few gotchas
  4. BurningBird's List of Links
  5. Dr. Bacchus' Solution to Preserving Links
  6. David's tips for redirection
  7. Narendra's experience migrating from TypePad to WP 1.5.1.2 (6/05)
  8. SquareFree Switching From Movable Type to WordPress
  9. Blau on issues when migrating a large site and the solution used
  10. Adam Stiles - Painless Switch from Typepad to WordPress
  11. Steven's experiences of moving from Movable Type 3.2 to WordPress 2.0
  12. Folivision's 2009 Guide to Typepad to WordPress Migration
  13. Exporting from Movable Type to WordPress