Import multiple WordPress posts with the same name

Update: A previous version of this post recommended modifying the importer, which was the only option at the time. Fortunately, WordPress Importer 0.6.2 implements the wp_import_existing_post filter which makes this much easier to implement. The content of this post has been updated to reflect this improvement.

By default, the WordPress import plugin will not create multiple posts with the same name which were created on the same date. I’m not entirely certain why this is the default behavior but in an era where WordPress is so much more than a blogging engine there is no limit to the number of cases where it isn’t desirable. Maybe you have a post type for business locations that is arranged hierarchically and each location has a child page called “Contact Us.” Maybe a hundred other things.

In such cases, I’ve found moving a site from my production server to the live server is problematic, because the WordPress Importer plugin discards all but the first instance of a post. Fortunately, this behavior is easily changed with a filter implemented in the WordPress Importer.

When the plugin iterates through all of the items in the import file, it checks to see whether or not it should create a post for the current item. Here, I implement a filter which basically tells the importer that there are no duplicate posts.

In your your theme or in a plugin, add the following filter:

/**
 * Tell the importer that none of your posts are duplicates.
 */
function my_filter_post_exists() {
	return 0;
}
add_filter( 'wp_import_existing_post', 'my_filter_post_exists()', 10, 0 );

By setting $post_exists = 0 you are telling the importer that the post doesn’t exist, which makes it work the way you probably want it to.

WordPress Training Screencasts

Kirk at Alt Tags has spent what I imagine is a tremendous amount of time putting together some great screencasts about installing, configuring, and using WordPress. These screencasts are great for anybody who wants to use WordPress for blogging or content management. There’s a wide variety of information available, so newcomers and experienced WordPress users alike will be able to learn plenty.

I’ve become a big fan of screencasts lately; Watching one is like piping computer information directly into your brain. If that sounds appealing, check out WordPressTraining.com.