Duplicate posts created when a post exists with the same post_title but different post_type
How to reproduce
Import an xml file containing a post with title Example but without post_date specified
Create another post with the same title Example but with a different custom post_type, for example news
Import that same xml file again. And it will create a new post with the same title instead of treating it as existing post.
Possible solution
Filter the post_type in $post_exists = post_exists( $post['post_title'], '', $post['post_date'] ); instead of checking the post_type later in if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) {
This is probably a corner case; And I'm sort of abusing this plugin.
So we are using the importer to continuously synchronizing the data from another system. And sometimes existing data gets synced across the systems.
post_date is irrelevant to that post type so it's always empty. Otherwise, it would have prevented this issue.
Meanwhile, other type of posts are continuously being published by writers, and may sometimes have the same title.
I'm just not sure if there's any particular reason why we are not filtering the post_type in the post_exists call. Maybe for backward compatibility?
Duplicate posts created when a post exists with the same post_title but different post_type
How to reproduce
Import an xml file containing a post with title
Example
but without post_date specified Create another post with the same titleExample
but with a different custom post_type, for examplenews
Import that same xml file again. And it will create a new post with the same title instead of treating it as existing post.Possible solution
Filter the post_type in
$post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
instead of checking the post_type later inif ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) {
https://github.com/WordPress/wordpress-importer/blob/449e2d3cbd54749c51cb896d411daa9bef14ae88/src/class-wp-import.php#L659 https://github.com/WordPress/wordpress-importer/blob/449e2d3cbd54749c51cb896d411daa9bef14ae88/src/class-wp-import.php#L675
Additional note
This is probably a corner case; And I'm sort of abusing this plugin. So we are using the importer to continuously synchronizing the data from another system. And sometimes existing data gets synced across the systems.
post_date
is irrelevant to that post type so it's always empty. Otherwise, it would have prevented this issue. Meanwhile, other type of posts are continuously being published by writers, and may sometimes have the same title.I'm just not sure if there's any particular reason why we are not filtering the post_type in the
post_exists
call. Maybe for backward compatibility?If not, I could work on a PR to update this.