What code are you using to insert the data? What do you wish to happen in the case of a duplicate entry?
Thread Starter
rajee
(@rajee)
Hi,
iam using wp_insert_post to insert data into wordpress .
In case of duplicate values , post should not be added in table
Hmm, that’s odd. That error message should not occur from entering a duplicate post, it sounds more like a post meta error, except it’s not an error to add multiple meta values. I don’t know where that error message is coming from actually. Regardless, you want to avoid duplicates.
What to do depends on how much must match to be considered a duplicate. If simply a matching title slug, you could first try to get a post with the proposed slug, and if successful, skip inserting the current post. If the criteria is more stringent, like matching title, content, author, date, etc., it makes more sense to query the posts table directly with $wpdb
methods. If a matching row is returned, skip inserting the current post.