How to Detect and Prevent Duplicate Posts in Automated WordPress

Last updated: November 10, 2026

Quick Answer: In automated WordPress publishing, duplicate posts are usually prevented with 3 controls: one stable ID, one pre-insert lookup, and one replay-safe webhook path. This article on How to detect and prevent duplicate posts in automated WordPress publishing shows how to keep one source item mapped to one WordPress post.

Duplicate posts in automated WordPress publishing usually come from retries, webhook replays, or a workflow run that fires twice. The fix is idempotency: give each post one stable identity, check WordPress before posting, and reject repeats at the webhook and database level. The steps below show how to stop the second publish before it becomes a second post.

Key takeaways

  • One post needs one stable ID from the moment automation starts.
  • A content hash helps catch near-identical repeats, not just exact reruns.
  • Webhooks need replay protection, or the same event can create two posts.
  • A pre-insert lookup on slug, external ID, or hash is the last cheap stop.
  • Database indexes matter, because a slow duplicate check is a failed guardrail.

What duplicate post prevention needs first

Picture this: your automation has already written the post, and the same payload is about to hit the WordPress REST API a second time after a timeout. You need one unique key, a lookup rule, and a place in your workflow where duplicate checks happen before insert.

Start with these inputs:

  1. A stable source ID. Use the post’s upstream ID, not the title. If your system does not have one, create an idempotency key such as site-2026-11-04-001.
  2. A content fingerprint. Hash the canonical title, body, and maybe the source URL. A SHA-256 hash is common because it gives a fixed signature for the same content.
  3. A WordPress field to store it. A custom post meta key is the usual choice, like _external_article_id or _content_hash.
  4. A slug rule. Decide whether slugs must be unique per site or unique per source. WordPress will often append a suffix like -2 if the slug already exists, which can hide a duplicate instead of preventing it.

When this is set up, a repeat run does not create a new row. It either matches the existing post or stops before insert.

What you should see when it works: the same input can run twice, but only one published post exists, with the same stored external ID or hash.

How do you stop the same post from publishing twice?

You stop it by making the publish step idempotent, then checking WordPress before every create call. A practical version of this uses a lookup on custom meta, slug, or hash before POST /wp-json/wp/v2/posts.

Here’s the core procedure:

  1. Generate the idempotency key before any publish call. Use the source post ID, or a deterministic hash of title plus canonical URL.
    Result: every retry carries the same identity.

  2. Store that key in your job record and in WordPress post meta. Use a custom field like _external_article_id.
    Result: your queue, logs, and CMS all speak the same ID.

  3. Run a lookup query first. Search for a post with that meta key, or check the slug if the meta field is not available.
    Result: if a post exists, the workflow can stop or update that record instead of inserting a new one.

  4. Create the post only if the lookup returns nothing. Send one POST to the WordPress REST API, then write the key back to the created post.
    Result: the first run inserts; the second run sees a match.

  5. Make the storage layer reject duplicates too. Put a unique index on the duplicate-prevention key in your integration database, not just in WordPress.
    Result: even if two workers race, only one wins the insert.

  6. Treat a timeout as unknown, not failed. If the request times out, re-check by key before you retry the create call; if needed, consult a WordPress developer or other professional and verify the behavior against the WordPress REST API docs.
    Result: a slow response does not turn into a double post.

A repeated request should return the same outcome, not a second record. The truth is, WordPress itself will not protect you from every automation race.

What you should see when it works: a second run finds the post by key, returns the existing post ID, and does not create a new published item.

Detect duplicates before they reach WordPress

Picture this: your workflow has three publish jobs in a row, all with slightly different titles but the same source text. You need a check that catches exact copies and near copies before the POST request leaves your system.

Use three detection layers:

  • Exact-match hash check. Hash the normalized title, body, and canonical URL. If the hash already exists, stop.
    This catches repeated workflow runs and replayed webhooks with the same content.

  • Slug lookup. Check whether the target slug already exists in WordPress. If it does, compare the stored external ID or hash before deciding to insert.
    This catches repeated runs that change only punctuation or capitalization.

  • Post meta lookup. Query WordPress for the source ID or hash before you publish. This is the strongest WordPress-side check because it does not depend on the title.
    It works even when the title changes from “Draft 1” to “Final Version.”

A content hash is best when the body is stable. It is weaker when your system injects timestamps, promo text, or author notes into the content before publish. In that case, hash the canonical source text, not the final rendered HTML.

What you should see when it works: a duplicate source record is flagged before publish, and your log shows “matched existing post” rather than “created new post.”

Protect webhooks from replay and double runs

Picture this: a webhook from your content system arrives twice, or a provider retries because it did not see a fast 2xx response. Without replay protection, the same event can trigger two WordPress posts in under 10 seconds.

Use these controls:

  1. Verify the webhook signature. Reject unsigned or invalid payloads before they hit the queue.
    Result: a fake or damaged event never starts publishing.

  2. Store the webhook event ID. If the provider sends an event UUID, save it in a dedupe table.
    Result: the second copy of the same event gets dropped.

  3. Set a replay window. Treat an event as valid only once inside a fixed time window, often minutes or hours depending on the provider; if the provider’s docs are unclear, consult a professional and check them directly.
    Result: old replays do not re-enter the pipeline.

  4. Acknowledge fast, process later. Return success after you have queued the job, not after WordPress finishes publishing.
    Result: the sender stops retrying while your system processes the job once.

  5. Lock the job key. Use a short-lived lock on the source post ID or event ID while the workflow runs.
    Result: two workers cannot publish the same item at the same time.

Webhook replay protection is not the same as retry logic. Retry logic says, “try again if the publish failed.” Replay protection says, “don’t treat the same event as new twice.” If you are unsure which rule fits your setup, consult a professional and confirm it with the webhook provider’s documentation.

What you should see when it works: duplicate webhook deliveries are logged and ignored, while the first event still publishes normally.

Use WordPress lookups and database indexes as a backstop

Picture this: the automation layer missed something, and a second request is already inside WordPress. A fast lookup on indexed post meta can still stop the duplicate before it is saved.

On the WordPress side, keep a lookup path that is cheap enough to run on every publish attempt. The common pattern is:

  • save the source ID or hash in postmeta
  • query that meta before insert
  • create a database index on the meta key you use most

Without an index, a meta lookup can become a slow table scan as the site grows. That is a bad place to rely on for duplicate detection. A unique index on a custom table is even stronger if your publishing stack stores staging records outside WordPress.

Use this order:

  1. Search by external ID.
  2. If no match, search by content hash.
  3. If still no match, check the slug.
  4. Insert only after all three checks fail.

That order works because external ID is the cleanest signal. Hash is the next best. Slug is useful, but it can change when editors rewrite titles or WordPress appends -2, -3, and so on.

You can also add a unique constraint in your own publishing database. That stops the duplicate before WordPress sees it, which is better than cleaning up after the fact.

What you should see when it works: duplicate checks stay fast, and the same post ID cannot be inserted twice even during a burst of jobs.

Common mistakes that create duplicate posts

Picture this: the workflow looks fine on paper, but a small shortcut lets duplicates through on a busy day. Most failures come from treating title matching as enough, or from assuming a timeout means the post never created.

Watch for these mistakes:

  • Using the title as the only key. Two different posts can share a title, and one post can have three title variants.
    Cost: false matches or missed duplicates.
    Do this instead: use source ID, then hash, then slug.

  • Hashing unstable content. If you hash HTML that includes timestamps, author names, or tracking snippets, the same post can produce a different hash on every run.
    Cost: the dedupe rule stops working.
    Do this instead: hash normalized canonical content.

  • Retrying create calls without a lookup. A network timeout can mean the post was created, but your system did not hear back.
    Cost: one timeout becomes two posts.
    Do this instead: check by key before retrying POST.

  • Ignoring webhook replay. If the sender retries and your handler is not idempotent, you will publish twice.
    Cost: duplicate content and messy cleanup.
    Do this instead: store event IDs and reject repeats.

  • Skipping indexes. A dedupe query that scans thousands of rows will slow down under load.
    Cost: lag, race conditions, and missed guardrails.
    Do this instead: index the lookup field you use most.

These fixes stack. You do not need one perfect control. You need two or three boring ones that agree with each other.

What you should see when it works: a retry, replay, or second workflow run stops at lookup time and never becomes a second published post.

How to test duplicate prevention without publishing twice

Picture this: your staging site has the same automation as production, and you want to see whether a repeat run creates another post. You need a test that uses the real lookup keys but a safe target like a staging site or draft-only endpoint.

Run four checks:

  1. Send the same payload twice. Keep the same source ID and content hash.
    Expected result: the second run finds the first record.

  2. Replay the same webhook event ID. Use the same signature and event ID, if your provider supports it.
    Expected result: the second event is rejected or ignored.

  3. Timeout the first request. Simulate a slow response, then rerun the publish flow.
    Expected result: your system checks for the existing post before creating a new one.

  4. Change the title but not the source ID.
    Expected result: the lookup still matches the existing post.

If any of those tests creates a second post, the gap is usually in one of three places: the key is not stable, the lookup is not happening before insert, or the dedupe record is not shared across workers.

This is also where your hub page on wordpress publishing architecture for post automation fits. The broader workflow matters, but this page is the piece that stops doubles.

What you should see when it works: repeated inputs collapse to one WordPress post ID across all four checks.

How do you stop the same post from publishing twice?

You stop it by giving the post one idempotency key and checking that key before every create call. The first request creates the post, and every later request finds the same post by external ID, hash, or slug. If the key is stable, the duplicate never gets a chance to become a new record.

How can automation safely retry without creating duplicate WordPress posts?

It can safely retry by treating the retry as a lookup-first action, not a blind second POST. The retry should search for the external ID or content hash first, then reuse the existing post if it exists. That matters after a timeout, because a timeout does not tell you whether WordPress saved the post or not.

Drafted with AI; not yet reviewed by a person.

Leave a Reply

Your email address will not be published. Required fields are marked *