Upgrading old WXR files with wp-cli

I recently had cause to try to import an old WordPress WXR export file into a more recent version of WordPress. There are some simple differences in the way the old files and the new files are formatted that keep this from working. The usual rigamarole for getting around this is to install a throwaway copy of the version of WordPress that the export file was generated with, import the file, and upgrade WordPress until you’re at the latest version. Then you export and the WXR is updated. That’s kind of painful and lame, though.

So, riding the wave of my recent fervor for wp-cli, I made a wp-cli command for doing the conversion. It’s called… convert-wxr.

Usage looks like this:

wp-cli --file=file-to-covert.wxr --outfile=converted-file.wxr

If you don’t specify an outfile, it just spews to the screen (you can redirect output to a file). It won’t clobber an existing file.

The script just does some simple regular expression and string replacements based on the differences I found between older and more recent WXR files. It’s entirely possible I missed some differences, but the conversions I tested seem to work well enough.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s