Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 7 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
1  
@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:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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