WordPress: Refresh W3 Total Cache when saving or updating a PODs item

When you create or edit a PODs element in Worpdress, W3TC refresh the cache of the modified page. But sometimes you also show its content on home page or other kind of page, and in those cases you need to flush the cache through the plugin admin panel. I was tired of doing this task every time I update something, so now I have a code to do it automatically.

You have to add this code in your function.php theme file.

// REFRESH W3 Total Cache AFTER SAVE/UPDATE
function refreshCacheOnSave($pieces, $is_new_item) {
    if (function_exists('w3tc_pgcache_flush')) {
        w3tc_pgcache_flush();
        w3tc_minify_flush();
    }
}

// refresh cache after PODs creation/save/update
add_action('pods_api_post_save_pod_item', 'refreshCacheOnSave', 10, 2);
add_action('pods_api_post_create_pod_item', 'refreshCacheOnSave', 10, 2);
add_action('pods_api_post_edit_pod_item', 'refreshCacheOnSave', 10, 2);

Escribe una comentario