Skip to content

Instantly share code, notes, and snippets.

@hatsumatsu
Last active August 23, 2018 09:59
Show Gist options
  • Save hatsumatsu/2ece512c520513897efb527b1e2bc20f to your computer and use it in GitHub Desktop.
Save hatsumatsu/2ece512c520513897efb527b1e2bc20f to your computer and use it in GitHub Desktop.
<?php
/**
* Flush W3TC page cache when custom post types are updated.
*/
function flushCustomPostTypesPageCache( $post_id ) {
$custom_post_types = array(
'post_type' => true
);
if( array_key_exists( get_post_type( $post_id ), $custom_post_types ) ) {
if( defined( 'W3TC' ) ) {
w3tc_pgcache_flush();
w3tc_dbcache_flush();
}
}
}
add_action( 'save_post', 'flushCustomPostTypesPageCache', 1000, 1 );
add_action( 'edit_post', 'flushCustomPostTypesPageCache', 1000, 1 );
add_action( 'delete_post', 'flushCustomPostTypesPageCache', 1000, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment