Chris Griffing

A Collection of Random Ramblings and Eclectic Interests

How To Flush W3 Total Cache Programmatically

March 14, 2014

When working with Wordpress you will likely need to create custom post types and you will also probably be working with a caching plugin. The problem is that caching plugins typically only flush the cache when normal posts and pages are published.

When I hit the search to find out how to programmatically flush the cache (of W3 Total Cache), I found nothing. I gave a quick glance at the structure of the plugin and realized, hunting down the flush cache method could take a while.

One more search and I found a pdf that contained this code snippet: if (function_exists('w3tc_pgcache_flush')) { w3tc_pgcache_flush(); }

Just put that inside of a "save_post" hook, and your cache will be flushed on each post save.

I leave it to the reader to go find the snippet to filter out auto-drafts.

© 2023 Chris Griffing