Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate postmeta records insertion #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sagarsdeshmukh
Copy link

Issue

  • On import of already existing attachment/post/page, the importer gives error "Page/Post/Attachment already exists." but imports the postmeta records from source.

Fix

  • Replace the function to add postmeta only if it's not exist

@dd32
Copy link
Member

dd32 commented Oct 12, 2020

Hi @sagarsdeshmukh, I apologise for how long this PR has sat here without any comment.

Does swapping from add_post_meta() to update_post_meta() break the expectation that WordPress can have multiple post meta records per name? For example, you can have name: animal value: cat and name: animal value: dog attached to the same post.

It might be better to explicitly only import postmeta/taxonomies when the post itself is imported, rather than relying upon the behaviour of update vs add.

@jmdodd
Copy link

jmdodd commented Dec 8, 2020

Part of the problem here is that there can actually be multiple identical post meta records per name (maybe for counting thumbs-up/thumbs-down as an example use case):

wp> add_post_meta( 5, 'foo', 'bar' );
=> int(200)
wp> add_post_meta( 5, 'foo', 'bar' );
=> int(201)
wp> get_post_meta( 5, 'foo' );
=> array(2) {
  [0]=>
  string(3) "bar"
  [1]=>
  string(3) "bar"
}

If the import is run multiple times, using add_post_meta will result in multiple instances of each post meta on a post because these are imported regardless of whether the post previously existed, and independent of how many times they already exist on a post.

@stevus
Copy link

stevus commented Aug 18, 2021

Should there be a check of existence of the key / value pair that is being imported, and if exists, do nothing? @sagarsdeshmukh @jmdodd that might solve the issue here?

@sagarsdeshmukh
Copy link
Author

This PR is being here for long period of time, I would like to ask the core team of this project, do you expect any action/input/changes from my end, please let me know?
cc: @ocean90 @jffng @boonebgorges @dd32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants