• Hi,

    Iam extracting data from a file and inserting into wordpress db. The data gets added at first but 2nd time the site refreshes i get the message as “Duplicate entry ‘test content’ for key ‘job_slug'”

    can anyone help

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    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

    Moderator bcworkz

    (@bcworkz)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Duplicate entry for "job_slug"’ is closed to new replies.