Allow WordPress to Import Posts with Existing IDs

Recently I faced a challenge when I had to import years worth of posts from a client’s old WordPress installation to a new one using WP’s Export/Import modules. The first step to export the posts into WordPress eXtended RSS or WXR was easy enough, but whenever I tried to import it to the new blog, it came with “Post Already Exists!” error messages.

The cause was multiple posts with the same ID had already existed on the new site. This could be because you tried many test posts, or added new post types and populated them before importing from the previous blog.

The solution was from this forum thread. You basically need to make WP Importer to ignore duplicate posts by making small change on the file, which is located on /wp-content/plugins/wordpress-importer/wordpress-importer.php:

[syntax_prettify linenums=””]
// comment the line below out around line 555
// $post_exists = post_exists( $post[‘post_title’], ”, $post[‘post_date’] );
$post_exists = false; // add this line

Problem be gone, but do be very careful to make sure you are not importing the same posts twice as you will find a hard time to remove them.

Leave a Reply