Title: w3tc_pgcache_flush_post() function is not working
Last modified: August 25, 2023

---

# w3tc_pgcache_flush_post() function is not working

 *  Resolved [Smith Nandagawali](https://wordpress.org/support/users/smithn67/)
 * (@smithn67)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/w3tc_pgcache_flush_post-function-is-not-working/)
 * Hi,
 * I am using the below code to purge the cache after custom post type updated but
   the function is not working.
 *     ```wp-block-code
       add_action( 'save_post', 'my_save_post_function', 10, 3 );
   
       function my_save_post_function( $post_ID, $post, $update ) {
   
         global $post_type;
   
         if( $post_type  == 'articles' ){
   
               //if(function_exists('w3tc_pgcache_flush_post')){
   
               if (w3tc_pgcache_flush_post($post_ID)){
   
                   echo __('<div class="udated"><p>Cache Emptied</p></div>');
   
               }else{
   
                   echo __('<div class="error"><p>Cache Not Emptied</p></div>');
   
               }
   
           } else{
   
               echo __('<div class="error"><p>Not an article</p></div>');
   
           }
   
       }
       ```
   
 * When I check `if(function_exists('w3tc_pgcache_flush_post')){` it works but when
   I put the ID w3tc_pgcache_flush_post($post_ID) and tried to flush, it is not 
   working. Can you please help me with the code.
 * Thanks in Advance

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/w3tc_pgcache_flush_post-function-is-not-working/#post-17000441)
 * Hello [@smithn67](https://wordpress.org/support/users/smithn67/)
 * Thank you for reaching out and I am happy to help.
 * Can you please try using function w3tc_flush_post( $post_id) instead?
   Thanks!
 *  Thread Starter [Smith Nandagawali](https://wordpress.org/support/users/smithn67/)
 * (@smithn67)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/w3tc_pgcache_flush_post-function-is-not-working/#post-17000811)
 * Hi, 
   Thanks for quick reply, I tried w3tc_flush_post( $post_id) it is still not
   working.
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/w3tc_pgcache_flush_post-function-is-not-working/#post-17001402)
 * Hello [@smithn67](https://wordpress.org/support/users/smithn67/)
 * Thank you for your feedback.
   Can you please share more details on what/why you
   are trying to do a CPT flush action and what/how you debugged and what output
   he’s received vs expected? It’d also be useful to know the details concerning
   the CPT you are trying to flush. We added the CPT flush a while back and it should
   be working and works fine.It may appear to not work because by the time your 
   function executes the CPT he’s trying to flush should already be flushed by the
   default process
 * Can you please confirm that the CPT you are trying to flush is still in the cache.
   If it’s not then the above is likely the case. If it IS still cached then there
   may be some issue that’d need debugging…at which point we’d either need access
   or the details concerning the CPT so we could possibly replicate/test
 * Thanks!
 *  Thread Starter [Smith Nandagawali](https://wordpress.org/support/users/smithn67/)
 * (@smithn67)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/w3tc_pgcache_flush_post-function-is-not-working/#post-17049895)
 * Hi,
 * In my project we are using Redis cache which clears the cache after 4 hours, 
   in between if I update any CPT the content change will not reflect for 4 hours.
   Therefore I want to purge the specific custom post type cache after update.
 *     ```wp-block-code
       add_action( 'save_post', 'my_save_post_function', 10, 3 );
   
       function my_save_post_function( $post_ID, $post, $update ) {
   
         global $post_type;
   
         if( $post_type  == 'articles' ){
   
               if (w3tc_flush_post($post_id)){
   
                   echo __('<div class="updated"><p>Working</p></div>');
   
               }else{
   
                   echo __('<div class="error"><p>Not working</p></div>');
   
               }
   
           } else{
   
               echo __('<div class="error"><p>Out</p></div>');
   
           }
   
          $msg = 'Is this un update? ';
          $msg .= $update ? 'Yes.' : 'No.';
          wp_die( $msg );
   
       }
       ```
   
 * Using wp_die() I am checking the function is working or not.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘w3tc_pgcache_flush_post() function is not working’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Smith Nandagawali](https://wordpress.org/support/users/smithn67/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/w3tc_pgcache_flush_post-function-is-not-working/#post-17049895)
 * Status: resolved