Nick Galvez

Developer and Musician

Use this hook to make the WordPress Importer update Duplicate Posts

The hook that makes this possible is wp_import_existing_post. Strangely enough, it didn’t show up on the Codex. Maybe because the importer is technically a plugin?

You can find this in the wordpress-importer plugin

* Filter ID of the existing post corresponding to post currently importing.
* Return 0 to force the post to be imported. Filter the ID to be something else
* to override which existing post is mapped to the imported post.
* @see post_exists()
* @since 0.6.2
* @param int   $post_exists  Post ID, or 0 if post did not exist.
* @param array $post         The post array to be inserted.
$post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );

Here’s a gist

I pasted this gist from github user ssuess in my functions.php file and then re-ran the import. It worked great!

Thanks, gister!