Category Archives: Uncategorized

Migrating to WordPress from Movable Type

I wrote this about a year ago as a sort of log of my trials migrating from movable type blogging to wordpress. It’s somewhat tongue in cheek / stream of consciousness so take it for what it’s worth, a little insight into the mind of a developer 😉

Moving from movable type (old ass version) to brand spanking new wordpress.

who wants to deal with cgi-bins, I mean really

movable type has an export feature, yay. Seems like it’s supported with some old version of wordpress. Let’s see, ok, generates proprietary format but it makes sense, does an export, looks like this:

AUTHOR: ChefQuix
TITLE: A little bit of everything…
STATUS: Publish
CONVERT BREAKS: __default__
CATEGORY: Armageddon

DATE: 09/14/2003 10:52:19 PM
I’ve always wanted to write a blog,

Alright, so quickly install wordpress.

Let’s play around, old ass instructions say modify some file called import-mt.php.

Uhoh, this does not exist in the new wordpress. Not suprising, who’s really dealing with legacy shit like this anymore?

Ok, let’s see what new WP can do. Look, import from movable type is built into the tools, yay, wait what’s this, send out FTP credentials to some 3rd party site so they can FTP stuff in? Or WP can FTP stuff in? Is this really the best and most secure way to import files? Yikes.

Grab files manually, install plugin, match up old username with new username, yes, look at that, lots of imports, everything is working great! Closer inspection though..

Cut off blog entries! The old poor quote handling, poor quote exporting situation. And the IDs, not the same, how can I make an .htaccess rule to map from old to new? Not good enough!

Truncate wp_posts, wp_comments tables, lets do this again.

First things first – change old Movable Type export to include the ID.

in <mt>/lib/MT/ add line in the export function:


Totally guessed at the template tag and it worked

now import.txt file as ID, will plugin work out of the box? probably not, but lets take a look

ok, import doesn’t support ID out of the box. Fair enough, it’s hard after all.

Add new case for the importer (in process_posts function):

} else if ( ‘POSTID:’ == $line ) {
$post->ID = trim( substr($line, strlen(‘POSTID:’)) );

Modify save_post function – post is saved using wp_insert_post function. Let’s take a look at what this function does and see how we can manually set the ID.


IMPORTANT: Setting a value for $post[‘ID’] WILL NOT create a post with that ID number. Setting this value will cause the function to update the post with that ID number with the other values specified in $post. In short, to insert a new post, $post[‘ID’] must be blank or not set at all.

Always roadblocks, so how do we work around this.

Lets take a stab in the dark, we’ll manually insert an empty table row with just the ID, then put the ID in the post variable and hope that wp_insert_post updates everything properly. Probably have to set post_date and post_date_gmt, I’m sure this is going to break a bit but oh well.

global $wpdb;

if (!empty($post->ID)) {
$wpdb->insert($wpdb->prefix . ‘posts’,array(‘ID’ => $post->ID),array(‘%d’));

scratch that, does wp_insert_post allow us to try to import the ID with the optional import_id parameter? Let’s try that less hacky way first
change modification back to:

} else if ( ‘POSTID:’ == $line ) {
$post->import_id = trim( substr($line, strlen(‘POSTID:’)) );

before we start the import up again, let’s try to clean up the file and fix some of these character encoding issues. Same old problem we always end up having – ‘,”,-,… – these characters always break. What’s the easiest solution? Load up the file in a trusty editor, find an offending character and search and replace. Get rid of the bad characters this way, then save it and do the import.

Ok, so the import runs again, but the IDs, they’re not matching up? What’s going on, time to dig deeper…

Add some debug code..

if (!empty($post->import_id)) {
printf(__(‘converting import_id %s’, ‘movabletype-importer’),$post->import_id);
$post->import_id = intval($post->import_id);
} else {
printf(__(‘wtf missing import_id’, ‘movabletype-importer’));

WTF? Importing post Are you also divergent, friend?…wtf missing import_id (2 comments)

Ok so that’s a problem it seems.

Ugh, bad code! Copy pasta from the wrong type of tag, of course it didn’t work. One more try, remove old POSTID bit and put in this:

} else if ( 0 === strpos($line, ‘POSTID:’) ) {
$post->import_id = trim( substr($line, strlen(‘POSTID:’)) );

Duhhhh think before writing code kiddos. Truncate wp_posts, wp_comments, and run one last time, this should fix everything for everyone in all instances…
And it works! Now that the IDs are normalized, I can htaccess example in old link from moving from MT to wordpress to make sure all pages get redirected to the new proper pages. Hoorray!

To make the redirects from the old URLs to the new ones, you just need to do a mysql query and copy and paste it into the WordPress .htaccess file:

mysql -u root -p -N -B -e “select concat(‘Redirect 301 /archives/000′, LPAD(ID,3,’0’), ‘.html /’, DATE_FORMAT(post_date, ‘%Y/%m/%d’), ‘/’, post_name, ‘/’) FROM perceptionalism_2.wp_posts”

(changing of course the user, database and what not for yourself).

This produces an output of:

Redirect 301 /archives/000005.html /2003/09/20/is-there-anybody-else-out-there-thinking/
Redirect 301 /archives/000007.html /2003/09/21/inspiration/
Redirect 301 /archives/000008.html /2003/09/29/wonder/
Redirect 301 /archives/000009.html /2003/09/23/are-you-a-bright/


And you’re done!

A Call to Arms

Politics have once again come to Canada, and I’ve become involved in the Conservative party because a long time friend is running for the federal government. I’ve been doing his webpage and I feel pretty bad about it as I don’t agree with anything his party stands for. I realized that I have to balance out this ‘evil’ I’m doing, so I’m going to be starting a non-partisan web forum for Winnipeggers to discuss the politics that are coming up. Along with the federal election we also have a mayoral election as our old mayor (Glen Murray) has stepped down to run for the Liberal party (and of course he’s running in the same riding as my friend).

Continue reading A Call to Arms


I’ve pulled the number one blog faux pas: I’ve pulled myself out of the online world for the last couple of weeks with no warning; with no explanation for my absence. For all of you few who read my blog I could be dead. I’m not, I’m still here poking around but I have been distracted. There were a number of events that lead to the derailing of my blog.

Continue reading Distractions

This is not a meme

There’s not much that can be said of Winnipeg that’s different from the rest of the world. Personally, I feel that Winnipeg spends most of it’s time absorbing other traditions fom cities and countries afar. There are though a few activities which remain unique to Winnnipegers. For example, do any of you attend socials of families to be? This is what I have been doing the last two nights: participating in a uniquely Winnipegan activity – the wedding social.
The wedding social is generally thrown by the groom and bride with heavy participation from the parental units. Entry is usually $10 and drink prices are below the bar average. Friends and family of the bride and groom are the ‘core’ invitees, however the ‘inner sect’ is encouraged to sell tickets to their friends in order to raise as much money for the wedding as possible. A chinese aution is held with 10-20 gift packages, ranging from collections of movies and popcorn to a basket of ‘pampering products’ including nick-nacks and chocolates. Sometimes there is a ‘grand prize’ – be it an xbox plus games or a dvd player and TV combo. Tickets are cheap and prizes are drawn at around midnight. Everyone goes with the intention of purchasing a fair amount of tickets in order to support the upcoming wedding.
Weddings can be expensive, and eveyone attending knows that the next one could be for their own, so they contribute a lot. Most socials are in a hall or gym, the odd one is held at a bar. Friday’s social was situated in a gym, tonights was in a bar. Needless to say this weekend has been a bit boozy for me, so I’ll cut this short and head to my comforting bed. If ever there was an idea that the rest of the world should adopt, this is it. It’s small, it’s fun and it brings people together. There is nothing quite as productive at bringing old friends back in contact then a wedding social. It’s harmless and fun, and it helps fund the already expensive weddings. Why don’t you think about it next time you or someone you know gets married?