• Hi,

    I am using the below code to purge the cache after custom post type updated but the function is not working.

    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

    (@vmarko)

    Hello @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

    (@smithn67)

    Hi,

    Thanks for quick reply, I tried w3tc_flush_post( $post_id) it is still not working.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @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

    (@smithn67)

    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.

    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.