Support » Installing WordPress » Importing Custom Fields from Movable Type

  • I’m looking to move two blogs to WordPress from some old MT installations I have. Thing is, both of them make quite heavy use of custom fields. Movable Type by default does not export that data, which is why I haven’t moved to this date. Believe I’ve figured out a way to get the custom data exported, but my question is this.

    What does the import on WordPress’ end do with custom data fields? Given they can be named anything, does WordPress just dump them into a custom field on it’s end?

    Optimally what I’d like to be able to do is to take the exported Movable Type data, and import it into WordPress, routing their custom data fields into ones that I define on my own. Can that sort of rerouting, or mapping of the fields be done on import?


Viewing 15 replies - 1 through 15 (of 20 total)
  • Found this post talking about the subject:

    But it’s three plus years old now. He mentions submitting it for a future version. Anyone know if it got included?



    Forum Moderator

    It didn’t get included in core, no. Try reviewing Importing_Content.

    @joe, you can transfer custom fields, but it is not part of the core import (at least, it wasn’t last time I checked).

    First you need to export the data, because by default MT does not do this – and getting it into the export is required for WP to import it.

    Second you need to update the import to process the data to the correct place. Since it isn’t defined, you can pretty much tell it where to go – uh, hope you know what I mean. 🙂

    Essentially you need to map each field to the new location. It isn’t horrible, but it can take some doing, especially if you have a lot of fields.

    I figured out the bit about getting the Movable Type custom data exported, so that end is covered.

    I was just looking at a way to figure out how to route the custom fields to where I want them to go on the WP side.

    I did review Importing Content, that’s where I got the link at, to be honest. There doesn’t appear to be info on exactly HOW to do this that I can find, which is why I posted.


    The easier of my two projects to move is a fan site I have for the Texas Rangers. For each game, I have results. In MT, the data about each game (outside of the blog entry) is in the following fields:

    1) Keywords: I have a URL there going to the official recap.

    2) Tags: a four digit number which is the date of the game in question. (0915, for example)

    3) The one actual custom field called “Game Score”, which is the score of the game.

    1 & 2 are part of the standard MT data structure, but I’m not using them in the way they were designed. In a perfect world, I’d want to take all three of these, and route them to a custom data field in WordPress, so I can deal with it that way.

    With no modification, I’m going to guess the WP importer will pick up 1 & 2, but dump ’em in those fields. Is there a way to reroute THOSE?

    I created a short test version of my mt-export.txt from MT (which is 7.4Mb) containing just half a dozen entries.

    I rejiggered the movable type export script to pick up the custom data, so that end is done. I created a virgin WP blog and imported the short six entry text file to see what happens.

    1) The data that was in “keywords” in Movable Type was dumped into “tags” in WordPress

    2) What I had in “tags” in MT appears to be gone, I can’t find where WP put it.

    3) Not imported, but I’m not surprised, it was a custom field.

    I can’t find info on how to modify the wordpress importer to route these things where I want them to go (which would preferably be a custom field for each of them). There any links somewhere showing that?

    Edit: Just had an idea. Since the Movable Type export file is raw text, I could I suppose take the exported data, and change all three I want to be custom data fields, if I can figure out how to get custom data fields imported on the WP side.

    That’s pretty much it.

    In the importer, you have tests like this:

    } else if ( 'BODY:' == $line ) {

    What you would do is add your own check:

    } else if ( 'FIELD:' == $line ) {

    Obviously, you would name the field appropriately here, so that it is uniquely identified – unless you want to save the body into a custom field.

    Then inside that test you would add the code to save it to the correct location, using the add_post_meta function.

    In order to do this, you’ll need to have the post ID (so make sure you do it after the post is saved), the field name (which you could probably hardcode) and the field value (which you are reading from the exported MT file).

    That should do it for you.

    Forgive the somewhat green posting, but how can I get the post ID on a post that’s being imported? iIf I’m reading that right jayseae, I need to double import?

    There’s several thousand entries in all, that would be a ton of work.

    Again, sorry if this all seems dumb. I’m sort of grasping this, but the lightbulb hasn’t totally gone off yet. 🙂

    My first attempt just generated a white screen on the importer, so I obviously did something wrong. Will have to continue to play with it to find the right combination. At least I know I can get this imported. Tkx.

    Near the top of the process_posts subroutine in the importer, there is a line that looks like this:

    $result = $this->save_post($post, $comments, $pings);

    That happens at the end of each post’s data, and it calls a routine (creatively called… “save_post”), and it is what actually inserts the post into the WP database. At that point, your post will have an ID.

    After that routine, you can use the ID, but the best thing to do is to first save each of your fields into a variable as you are processing them – perhaps an array, depending on the number (1-2 fields might be simpler as individual ones, otherwise an array with all the fields might be easier, that is up to you). If you do not save your fields, you will not have the ID in order to save them as custom fields, and you would have to save them elsewhere.

    Then once the post has been saved – and assuming that the post does not return because of an error – you have an ID, which means you can add code to handle the saving of your fields. This could be immediately after the code above, or it could be within the save_post routine itself, to keep things somewhat organized if you prefer that avenue.

    It would be nice if there was a way to add a filter to handle this, rather than hacking at the code itself, but it does not appear that you can do so – you need to process the text in the file and then you need to adjust/interrupt/piggyback on the save_post routine as well.

    I’ve got to break for a bit, but this looks like good info to get me going in the right path. Thank you, and I’ll report back later today on my progress. 🙂

    OK, after a couple of hours of messing with this, I’m having difficulty figuring out the bit that will make it work. At first I was crashing the importer, and I’m not doing that, but it’s not importing the data I’m talking about. Here’s what I’m dealing with:

    That’s the short export file from Movable Type with about 6 entries or so in it. Not going to do the one with multiple thousands until I get the system locked down. 🙂

    There’s three parts from each entry I want to import. They’re these:


    “TAGS:” I want to import to a custom field called GAMEDATE
    “KEYWORDS:” I want to import to a custom field called MLBURL
    “SCORE:” I want to import to a custom field called SCORE

    Tags has a different format than the other two, plus it’s not always there. In looking at the MT importer, it appears I’ll have to come up with two bits of code to get this all imported. I’ve been trying with just tags so far before I moved to the others. The most recent attempt was this sequence of code.

    } else if ( 'TAGS:' == $line ) {
    				$tags = trim( substr($line, strlen('TAGS: ')) );
    			        add_post_meta($post_id, 'GAMEDATE', $tags);

    I found that line you’re talking about, but if I put my code attempt RIGHT after that line,it munges up the import pretty good. If I put it down with all the other else if’s, it doesn’t crash anything, but nothing gets imported.

    Which tells me my code is screwed up. I tried replicating bits of code from the other import sections that work from similar lines around the “TAGS:” line in my import file, but they don’t seem to work.

    This is obviously a non coder here trying to cobble this together, so if you have any further advice, I’d appreciate it.

    That’s a bit more complex than where we started. 🙂

    What will happen – by default, mind you – is that tags will be imported as tags. I am fairly certain, but have not looked at it in that much detail, is that keywords will also be imported as tags. But put those two aside for the moment.

    The score is the only one addressed by the portion above. You would need to add a separate line to address that section. Something like this:

    } else if ( 'SCORE:' == $line ) {

    That would allow you to save the score into another field – call it $score for the sake of discussion – and then you could save that field into a meta field after saving the post. Something like:

    add_post_meta($post->ID, 'SCORE', $score);

    Where it gets (more) complicated is that you also want to redefine at least the tags function, to not save the tags as tags, but as a custom field, and perhaps do the same as keywords, which typically are saved as tags.

    That means those functions would need to be redefined – generally the same principle, but you would need to make sure the original functions were commented out or otherwise not being run (you could also remove them).

    Possible nevermind: In a quick search of the code, there is actually no reference to tags other than in reference to the comments – and I did not see any in your sample export either. So you may need to add this to your export and you would not have to worry about it on the import. Keywords may be the only issue here, the backwards of what I mentioned earlier.

    There is the line TAGS: in a couple of my fields. It’s not in all of them. If you looked at just the first on the linked code, you won’t see it, but it’s in all but two of the example entries.

    Keywords get imported as “tags” in WP if I don’t mess with the code at all. My code attempt stopped them from being imported as tags, but didn’t import it as a custom field, so something’s happening there.

    I’ll use your code fragment and see where I get.

    Fair warning to my hair. Might get pulled out. 🙂

    Delete post. nevermind.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Importing Custom Fields from Movable Type’ is closed to new replies.