Hello,
You can do it like this:
add_action( 'save_post', 'my_custom_clear_cache', 10, 1 );
function my_custom_clear_cache( ) {
$GLOBALS['quick_cache']->clear_cache();
}
Hi the following code clears all the cache right? how about if I just want to clear a cache of a specific page or URL, how will I do that in function.php ?
add_action( 'save_post', 'my_custom_clear_cache', 10, 1 );
function my_custom_clear_cache( ) {
$GLOBALS['quick_cache']->clear_cache();
}
You should be able to accomplish that by passing the page or post ID to the auto_purge_post_cache() function like this:
add_action( 'save_post', 'my_custom_clear_cache', 10, 1 );
function my_custom_clear_cache( ) {
$post_id = 123;
$GLOBALS['quick_cache']->auto_purge_post_cache($post_id);
}
wow thank you for the reply!
another question 🙂
how about clearing the cache of the category / archive page and a custom page. For example in my site, I created a custom page that lists all posts with recent updates on custom fields and content (e.g. mydomain[.]tld/mycustom.php —> which I 301 to –> /updates/ (cached via the ?qcAC=1 parameter).
Those commands above are clearing the cache immediately?
how about clearing the cache of the category / archive page and a custom page.
The custom page would be cleared the same way, by passing the ID of the custom page to auto_purge_post_cache(). There is no function currently to clear a specific category cache.
There is a feature request open for specifying a list of specific URIs that should be purged when a post is published, so after that feature gets implemented there will likely be a function you can call to purge a specific URI. You may want to follow that GitHub issue for updates.
If you have any further questions, please open a new support thread, as this one is already marked as resolved.