Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Fix Scheduled Posts That Silently Publish Twice Because Two Separate Cron Triggers Fire in the Same Minute

- 21.10.26 - ErcanOPAK

📝 The Post That Published Itself Twice

WP-Cron isn’t a real system scheduler – every single page load on the site is what actually checks whether any due cron event is overdue and fires it, with no built-in lock against two requests landing in the same second and both deciding the same scheduled post is due. On a moderately busy site, or one where a caching layer, a monitoring uptime checker, and a real visitor all happen to load pages within the same minute, two separate requests can each independently trigger the publish event for the same post before either one has a chance to see the other already did it.

🔎 The Problem

Scheduled post set for 9:00 AM, site also has an external uptime
monitor pinging every 60 seconds and object caching enabled

What actually happens around 9:00 AM:
1. An uptime monitor request lands at 8:59:58 and triggers
   wp-cron.php's check for due events - the post isn't due yet by a
   couple seconds, so nothing fires.
2. A real visitor loads a page at 9:00:02, wp-cron.php runs again,
   sees the post is now due, and starts publishing it.
3. Before that publish finishes writing the post status, a second
   near-simultaneous request (another visitor, a REST API call from
   a mobile app, a second monitor hit) also runs its own wp-cron.php
   check, independently sees a status that still looks "not yet
   published" in its own cached read, and fires the same publish
   event a second time.
4. Depending on the theme and any publish-triggered plugin (social
   auto-poster, email notification, webhook), the result is the same
   post appearing to publish twice in quick succession, each trigger
   re-running its own "on publish" side effects independently.

Nothing in the Site Health or scheduled posts screen ever shows two
separate publish events - WordPress itself only sees one final post
status, "publish," regardless of how many times the transition into
it actually fired along the way.

✅ Fix: Give WP-Cron an Actual Lock, Not Just a Schedule

  • Disable the default page-load-triggered cron entirely by setting DISABLE_WP_CRON to true in wp-config.php, and instead run wp cron event run –due-now (or call wp-cron.php directly) from a real system cron job on a fixed interval – a single external trigger removes the race between multiple concurrent page loads each deciding independently that an event is due.
  • If a plugin-based solution is preferred over editing wp-config.php, use a cron-control plugin that adds an actual locking mechanism around event execution, so a second near-simultaneous trigger can see an event is already running and skip it instead of firing it again from scratch.
  • For any custom code hooked to a publish-transition action, make it explicitly idempotent – check a post meta flag before running the side effect (sending a notification, posting to social, calling a webhook) and set that flag as the very first thing the hook does, so a duplicate trigger finds the flag already set and does nothing.

🚨 Why This Is Dangerous

  • Because WordPress’s own post status only ever shows the single final ‘publish’ state, there’s no built-in audit trail that even proves the duplicate firing happened – diagnosing this usually means correlating timestamps in a separate social-posting plugin’s own log or an email provider’s send history, not anything inside WordPress itself.
  • The failure mode gets dramatically worse the more traffic or monitoring a site has, which means a staging environment with a single developer casually clicking around almost never reproduces it, right up until the exact same scheduled-post setup goes live on a busier production site and starts double-firing immediately.

WP-Cron was never a scheduler waiting quietly in the background – it’s a race that every single page load enters, and a scheduled post only avoids running twice because most of the time, nobody actually wins at the same instant.

— WordPress Admin

Related posts:

WordPress: Fix a Custom Nav Menu Walker Class Silently Being Ignored Because the Theme's wp_nav_menu...

WordPress: Fix a Custom Nav Menu Walker Class Silently Being Ignored Because the Theme's wp_nav_menu...

WordPress: Fix a Scheduled Post That Silently Stays in Draft Because WP-Cron Never Actually Fires

WordPress: Fix a Scheduled Post That Silently Stays in Draft Because WP-Cron Never Actually Fires

WordPress: Fix Featured Images Disappearing From Older Posts After a Theme Switch Because the New Th...

WordPress: Fix Featured Images Disappearing From Older Posts After a Theme Switch Because the New Th...

Views: 5

Post navigation

The AI Prompt That Turns a Pile of Paper Receipts Into a Line-by-Line Expense Report You Can Actually Submit
Docker: Fix docker compose up –scale Silently Failing to Add Replicas Because a Fixed Host Port Mapping Is Still Declared for That Service

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com