WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a question.

How can I clear the cache when a post is submitted ? Actually, I need to clear two speficied pages which display these articles ? By default, I have noticed the index.php is cleared automatically when a post is submitted. But not Archive page or Category page...

Thanks in advance.

EDIT : By the way, how to clear only a specific page with W3 Total Cache ?

Example : Clear /blog.php

share|improve this question

closed as off-topic by birgire, gmazzap, Pieter Goosen, ialocin, Johannes Pille Aug 24 '14 at 11:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – birgire, gmazzap, Pieter Goosen, ialocin, Johannes Pille
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 9 down vote accepted

Hm, I am not sure but I think that whole cache should be invalidated on publishing of new post... Had you tried to enable debug info in W3TC and check why are those pages aren't refreshed?

As for manual cache clear, from plugin's FAQ:

How can I flush the cache without using the WP Admin interface?

It's possible to empty the entire cache or simply purge the cache of a single post / page:

Purge the entire page cache: if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); }

Purge a single post / page by passing it's ID:

if (function_exists('w3tc_pgcache_flush_post')) { w3tc_pgcache_flush_post($post_id); }

share|improve this answer
Wow ! w3tc_pgcache_flush_post($post_id); seems really good. I'll try this and I'll be back to you. Can you give the FAQ of W3TC where you found this please ? – Steffi Apr 12 '11 at 14:58
@Steffi see menu of installed W3TC :) – Rarst Apr 12 '11 at 15:04
@Rarst Thanks ! And is it possible to set multiple $post_id with the function w3tc_pgcache_flush_post($post_id) ? – Steffi Apr 12 '11 at 15:11
@Steffi don't know, you can always call it several times. – Rarst Apr 12 '11 at 15:12
@Steffi no idea, as I said in my answer - I don't think it should remain cached when new post is posted anyway. You might be better off asking W3TC developer about your issue. – Rarst Apr 12 '11 at 16:14

I have written a post on my blog which directly answers this topic. My post covers in detail, how to install the code, how to use the code, and what the code does.

If you read my blog post, you will be able to easily, automatically clear caches on the WordPress action hook: save_post, from the WordPress plugin: W3 Total Cache.

Automatically clear all caches with W3 Total Cache

You have the following options for which caches to clear upon the WordPress action hook save_post:

    Calls the W3TC function: w3tc_dbcache_flush();
    Clears the DB caches completely. Note: Doesn’t clear MySQL Query Cache, just WP based DB caches.
    Calls the W3TC function: w3tc_minify_flush();
    Clears the minified content caches completely.
    Calls the W3TC function: w3tc_objectcache_flush();
    Clears the object caches completely.
    Calls the W3TC function: w3tc_pgcache_flush();
    Clears the Page Cache completely.
    Calls each of the W3TC functions in one instance.
    Attempts to clear all W3TC caches completely.
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.