After publishing or updating a WordPress post, an administrator may see the new text while visitors still see the old version. In most cases, this is not a WordPress error or an Object Cache issue. The HTML page may still be stored in Nginx FastCGI Cache, Varnish, a CDN, or a caching plugin.
To make changes appear promptly, you need to clear the correct caching layer at the right time. A reliable approach accounts not only for the post URL but also for related archives, including the blog page, categories, tags, RSS feeds, and sitemaps. At the same time, clearing the entire site cache after every publication is usually unnecessary.
Why WordPress Shows an Old Version of a Page
Several independent caching layers may operate in WordPress at the same time. The clean_post_cache() function clears the post object cache and related internal WordPress structures, but it is not required to remove ready-made HTML already stored by the web server or CDN.
When a visitor opens a URL, the request may never reach PHP. Nginx, Varnish, a CDN, or a caching plugin can return an already-generated HTML response. Therefore, changing a post in the database does not automatically update the page cache.
Object Cache, such as Redis or Memcached, is a separate layer. It stores query results and WordPress objects but does not always handle the complete HTML page. Calling wp_cache_flush() may clear the object cache, but it will not remove a FastCGI Cache file or purge a CDN.
- Object Cache: objects, query results, and WordPress data.
- Page Cache: ready-made HTML for a specific page.
- CDN cache: a copy of the response on an edge server.
- Browser cache: a local copy that the server cannot remove directly.
When to Trigger Cache Purging
Purging should be tied not only to publishing a new post but also to other changes that affect the HTML. The transition_post_status hook is useful for handling publication, unpublishing, and returning a post to the published state.
However, editing an already published post does not always involve a status transition: the status may remain publish. Therefore, editing the title, text, image, or taxonomies requires an additional save_post hook or other logic that responds to an actual post update.
Avoid performing an expensive purge directly during every administrator request, especially when the purge calls an external CDN. This may be acceptable for a small site, but an active resource is better served by placing URLs in a queue and combining duplicates.
- A new post is published.
- A published post is updated.
- A post is moved to draft, pending review, or scheduled status.
- The category, tag, image, or publication date changes.
- The sitemap or another index document changes.
Which URLs to Purge After Updating a Post
The minimum set for a new or updated post is its canonical URL. However, visitors may find the content through the blog archive, a category, tags, or the author page. If these pages display the post title, date, excerpt, or image, their cached versions may also become outdated.
The URL set depends on the site structure. You do not need to purge every category and tag without exception: only purge the taxonomies associated with the specific post. If the publication date or content order changes, include the relevant archive pagination pages.
Purge the sitemap when it contains a changing lastmod value, publication date, or new URL. On large sites, a sitemap may be divided into an index and child files, so the purge mechanism must account for the actual structure.
- The canonical post URL.
- The main blog page or post archive.
- Category and tag pages associated with the post.
- RSS or other public feeds, if they are cached.
- The sitemap or sitemap index.
- The author page or special archives, if they are used.
Example WordPress Logic
The following framework collects URLs to purge after a post is published, unpublished, or updated while already published. The webhva_purge_urls() function is an adapter that must be connected to the specific purge mechanism used in your infrastructure.
The code does not perform universal cache clearing because the APIs and rules for Nginx, Varnish, CDNs, and different plugins vary. Before using it, check which URLs your cache accepts and whether it requires a separate HTTP request, a server command, or an API token.
- Check the post type so that pages, products, or internal types are not purged unnecessarily.
- Do not run the code for revisions, autosaves, or repeated internal saves.
- Remove duplicate URLs before sending them to the purge system.
- For bulk imports, replace the direct call with queueing URLs.
add_action('transition_post_status', function ($new_status, $old_status, $post) {
if ($new_status === $old_status || $post->post_type !== 'post') {
return;
}
if ($new_status === 'publish' || $old_status === 'publish') {
webhva_queue_post_cache_purge($post->ID);
}
}, 10, 3);
add_action('save_post_post', function ($post_id, $post, $update) {
if (!$update || wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
return;
}
if ($post->post_status === 'publish') {
webhva_queue_post_cache_purge($post_id);
}
}, 10, 3);
function webhva_queue_post_cache_purge($post_id) {
$post = get_post($post_id);
if (!$post || $post->post_status !== 'publish') {
return;
}
$urls = [get_permalink($post)];
$blog_url = get_post_type_archive_link('post');
if ($blog_url) {
$urls[] = $blog_url;
}
foreach (get_the_category($post_id) as $category) {
$urls[] = get_category_link($category->term_id);
}
foreach (get_the_tags($post_id) ?: [] as $tag) {
$urls[] = get_tag_link($tag->term_id);
}
$urls = array_values(array_unique(array_filter($urls)));
// Connect your CDN, Varnish, caching plugin, or server-side purge API here.
do_action('webhva_purge_urls', $urls, $post_id);
}
How to Connect a Specific Caching Layer
For Nginx FastCGI Cache, the clearing method depends on the configuration. It may involve deleting a cache file using a known cache key, sending a request with the PURGE method, or calling a separate internal endpoint. Do not expose such an endpoint without access restrictions; otherwise, third parties could force cache purges.
Varnish commonly uses PURGE or BAN with a rule that identifies the URL and host. Add IP verification, a secret header, or another authorization mechanism. BAN may be more convenient when you need to remove a group of pages based on a condition.
For a CDN or caching plugin, use its official API or recommended WordPress hook. Do not combine multiple purge methods arbitrarily: a plugin may control its own cache but have no access to the CDN cache.
After connecting the adapter, the logic should return an error if the purge fails. You can log the error and retry it through a queue. Silently ignoring errors creates a situation where publication succeeds formally, but users continue to see the old page.
- Identify which component is returning the old HTML.
- Check the purge API documentation for that component.
- Restrict access to the endpoint or API key.
- Log the URL, time, HTTP status code, and error message.
- Add retries for temporary network failures.
What to Check If the Old Version Still Appears
First, open the page in a private window or make a request without the browser cache. Check the response headers: X-Cache, Age, Via, Cache-Control, and service-specific CDN headers can show which layer returned the response and whether it was a HIT or MISS.
Compare results from different networks or regions if the site uses a CDN. Purging the origin server does not always remove copies from edge nodes immediately. Also check whether mobile and desktop versions are cached separately.
If the purge succeeded but the page is old only in the browser, the cause may be a local cache, service worker, or caching at the corporate network level. If only an authenticated user or only a guest sees the old text, check the different caching rules for cookies and headers.
- Check the page in an incognito window.
- Review response headers using developer tools or curl.
- Check the URL with and without parameters.
- Confirm that the canonical URL and sitemap point to the expected address.
- Review purge logs and cache lifetime.
- Check for separate caches in the CDN, proxy, or browser.
curl -I https://example.com/example-post/
Common Mistakes and a Safe Strategy
The most common mistake is calling wp_cache_flush() and expecting it to clear all HTML cache. Another problem is clearing the entire site after every update. This creates load spikes, increases the number of slow MISS requests, and can reduce performance for all visitors.
Another mistake is purging only the post URL. If the title or image changes in a category archive, visitors will still see the old listing. The opposite extreme is adding every possible URL to the purge without analyzing dependencies.
For bulk imports, use a queue: collect URLs, combine duplicates, and process them in batches. After a large series of changes, it may be more efficient to clear the defined archives once rather than send hundreds of identical requests.
- Do not confuse Object Cache with Page Cache.
- Do not use a global flush as the standard response to publishing.
- Do not trigger a purge for every autosave.
- Do not leave the purge endpoint open to everyone.
- Do not treat a successful post save as proof that the HTML cache was successfully cleared.
Frequently asked questions
Is calling wp_cache_flush() after publishing enough?
No. wp_cache_flush() applies to the WordPress object cache and is not a universal way to clear HTML stored in Nginx FastCGI Cache, Varnish, a CDN, or a caching plugin. You need to purge the specific layer returning the old page.
Why does transition_post_status not run after editing a published post?
This hook is intended for transitions between statuses. If the post remains in publish status, the change may not be a status transition. For these cases, add save_post, post_updated, or a mechanism used by the specific editor or plugin.
Do I need to purge the cache for every category and tag?
Usually not. Purge the categories and tags associated with the post, along with any other archives where the content actually appears. If the post order or publication date changes, include the relevant pagination pages.
How should I clear the cache after a bulk post import?
Do not send dozens or hundreds of purge requests at once. Add URLs to a queue, remove duplicates, process them in batches, and provide retries. For large changes, you can clear the required archives separately after the import is complete.
How can I determine which cache is returning the old version?
Check HTTP response headers and the logs for Nginx, Varnish, the CDN, and the caching plugin. Compare responses for guests and authenticated users, and check the page from different networks. This helps distinguish server, CDN, and browser cache.
Conclusion
Keeping a page current after publication depends not on a single WordPress call but on the entire caching chain. clean_post_cache() and wp_cache_flush() do not replace an HTML cache purge when the page is served by Nginx, Varnish, a CDN, or a caching plugin.
The practical approach is to respond to post publication and updates, identify related URLs, purge only the required resources, log the result, and use a queue for bulk changes. This helps the site display new content quickly without unnecessary global cache clearing.