Over on Learning Movable Type, Jaclyn asked why she wasn't able to get tags imported to a new MT4 installation. While Movable Type 4 includes an entry's tags in the import specifications, and also exports those tags when saving the data, no prior versions have exported the tags, even though tags have been natively supported since MT 3.3x. Luckily, it's easy to get them.

First, make a backup of ImportExport.pm from your original Movable Type installation, which is the Perl module that handles the export. Do this because you want to make sure that you have a good copy, just in case something goes awry. Put this backup in a safe place, and work with the copy of the file, just in case. Ready? Good.

Using your copy, open ImportExport.pm and locate the line that looks like this:

sub export {

In any version of MT 3.3x (that is, MT 3.31, MT 3.32, MT 3.33, MT 3.34 or MT 3.35), this is on line 516. This indicates the start of the export subroutine. Once you have located this line, scroll down a few lines and locate these lines:

DATE: <$MTEntryDate format="%m/%d/%Y %I:%M:%S %p"$>
-----

This is where you are going to insert the information. Change these two lines so that they look like this:

DATE: <$MTEntryDate format="%m/%d/%Y %I:%M:%S %p"$><MTEntryIfTagged>
TAGS: <MTEntryTags glue=","><$MTTagName quote="1"$></MTEntryTags></MTEntryIfTagged>
-----

What you have done is insert a section of code that will include the tags only if there are tags on the entry. Make sure you include the dashes, as that is a necessary part of the formatting.

By wrapping everything in the MTEntryIfTagged container, you are sure to only include the line if the entry in question has tags. This probably isn't completely necessary, but it makes things tidy, so it's a good idea to include it. The rest of the line just formats everything correctly, producing the necessary information for a valid import.

After making this change, save your changes and exit. Then upload the file to your server and run your export again. Now you should be able to see the tags in your exported file, and you can import these to your MT installation.

There is one difference in this and the MT4 version, and that is that the "include_private" attribute doesn't exist in MT3. This should mean that you get all the tags on the entry, including private tags. But just in case, make a note of any private tags that you have, as you might need to update them later.

Tutorial cross posted on Learning Movable Type.

Comments (8)

Chad, thank you so much for the assistance, and answering my question! I am using MT 3.35 so this was a huge help.

Hi Jaclyn -

Glad that it helped!

Hi Chad,

I got around to testing it today, and when I got to importing, it didn't work. The tags exported, but didn't import.

I tried roughly 10 different ways before I gave up... for now.

I think it has something to do with tags not being imported, or a command that doesn't tell them to import (i.e. categories, comments, etc.) because they're exporting fine.

Thanks again for answering my question anyway.

Hi Jaclyn -

If you look at the ImportExport.pm module from MT 4.01, you should see a line that looks like this:

} elsif ($key eq 'TAGS') {

That's on line 203. What is happening is that each line is split into two parts on the colon. The part before the colon is in the field called $key, so it's checked to make sure it is called TAGS (case does matter!).

If it finds that the line starts with TAGS (that this field is there), it checks to see if there is something after the colon - this will be in the field $val. At this point, it sets the tags for that entry to the value of that field (actually, it splits them up and sets the tags individually). Even though MT allows you to set a tag separator other than a comma, it has to be a comma in the file, because it doesn't check for anything else.

It's really fairly simple - but if it's not working, check to make sure that your line looks like this:

TAGS : Foo, Bar

That is, make sure that TAGS is capital, that you have colon and then you have your tags, separated by commas. The spaces around the colon aren't necessary. It can just as easily look like this:

TAGS:Foo, Bar

And it should work fine. But the case of "TAGS" is important, as is the colon and the comma as a separator. Also, make sure that you are importing using MT 4.01 - if you are using the (original or modified) version of ImportExport.pm from MT 3.3x, it won't work!

I hope this helps!

I went back to the original way, and examined how the tags were exporting.

This was how they looked like:

TAGS: "foo","bar"

which, by your comment, is incorrect.

I took out the quote="1" and added a space after the comma, and the exported tags looked like:

TAGS: foo, bar

I imported and the tags are still not there. Perhaps there isn't a way to import tags yet.

Thanks again for your help.

Hi Jaclyn -

I'm not quite sure why it isn't working for you. I don't think that the quotes should matter. I just wrote that quickly, not thinking about them, but that was good thinking to try it out.

Has anyone got this to work with 4.2? I exported the tags, and they show up right after the AM or PM, like this, AMTAGS, or PMTAGS. I've tried to import them, but get the following error:

An error occurred during the import process: Invalid date format

If I go in and put a space between the AM and TAGS or even a return, it still doesn't work at all.

Any clues?

Hi David -

I haven't tried importing with MT 4.2 - but you'll definitely want to have it on a different line, for similar reasons to those described above. If you have AMTAGS (or PMTAGS), then it won't be able to tell that you have a new set of data there - it will look like a part of the datestamp (which will naturally be wrong)!

Leave a comment