This is a technical post sharing a problem I solved today. Hopefully it’ll be useful to some folks :)

The Problem: WordPress RSS Importer Only Imports Categories

I’m currently working on a Drupal-to-WordPress migration. We’re automatically migrating their blog posts, so using an RSS feed—set up with a Drupal View—is the simplest way to do that.

One downside of this approach in this case is that RSS only supports categories and therefore the WordPress RSS Importer only imports Categories. That turned out to be not very hard to solve.

Quick Note: The PHP7 Version of the Plugin

The current version of the plugin (v0.2) does not support PHP7 at all. Therefore, if you’re on PHP7, you’ll want to use this version 0.3 on GitHub until the official plugin repository version gets an update.

Importing Tags instead turned out to be slightly trickier than expected because there is no wp_create_tags() function in WordPress. Because of that, I had to loop through each category to first create its tag and then assign the resulting term to the Post.

Here’s the code. Take it and completely replace the Lines 161-162 of the v0.3 plugin:

BONUS! Adjusting the Imported Author

The RSS Importer also does a rather “dumb” thing and sets the imported post author to the user with the ID of 1. That happens even if there is no user with that ID! (And there shouldn’t be!) Doik!

To fix that issue, just update the $post_author value of “1” on Line 136 to the ID of the user you want to use instead. It likely wouldn’t be too hard to read the “dc:creator” value out of the feed and map those to different WordPress user accounts, but I didn’t need to do that in this case.