• I have a plugin that uses a shortcode and the shortcode has a value that needs to be change. I want that after the value of the shortcode changed, the post that uses that shortcode flushes its cache so the changes will take effect after the change.

    I’ve added the following code to flush the single post without luck.

    if (function_exists('w3tc_flush_post')){
        w3tc_flush_post($post_id);
    }

    I’ve also tried to use the following code to flush all cache without luck as will.

    if (function_exists('w3tc_flush_all')){
        w3tc_flush_all();
    }

    Is there something I need to initialize before calling this function?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @jaypabs,

    The first code should work just fine. The fact that it doesn’t work might be caused by some error which should be logged in PHP logs.

    Thread Starter jaypabs

    (@jaypabs)

    Hi Marko,

    Thank you for the reply. I can’t find any error in my php log. I already enabled debugging in wp-config.php.

    The second code doesn’t work also. It really doesn’t need any initialization to call w3tc_flush_post or w3tc_flush_all function?

    Thread Starter jaypabs

    (@jaypabs)

    Hi Marko,

    Did you test it on your end? If you can double check that it’s working, please do let me know. Because I’ve already tried it myself several times and it’s not really working.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello,

    That function is already defined

    You only add the w3tc_flush_post($post_id) call where you wants pages to be flushed

    Thread Starter jaypabs

    (@jaypabs)

    Hi Marko,

    Did you try it or double check if it’s working?

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @jaypabs,

    This is the correct call. Where did you add the code?

    Thread Starter jaypabs

    (@jaypabs)

    Hi Marko,

    I put the code in my plugin behind the update button. When the update button is clicked, the following code will be called:

    if (isset($_POST['edit_result']))
    {
        ...
    			
    	if (function_exists('w3tc_flush_post')){
    		w3tc_flush_post($post_id);
    	}
    	
        /*if ( function_exists( 'w3tc_pgcache_flush' ) ) { 
            w3tc_pgcache_flush(); 
        }*/
    	
    	...
    
    }

    Thanks for the help.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello,

    If the shortcode is on a page, and if you change the shortcode and to publish that, you need to click the update button on the page you are editing. We already have the Page Cache Purge Policy for that.
    If you’re using the shortcode in a widget, then there’s an action/filter to fire a callback after the update button on the widget is clicked, but there is no post_id there, so you cannot use w3tc_flush_post that way.

    Thread Starter jaypabs

    (@jaypabs)

    Hi,

    Yes, the shortcode is on a page. When we change the value of the shortcode and after clicking the update button, it fires this code: w3tc_flush_post($post_id);

    But it’s not working. BTW, what’s the action/filter to fire a callback when the update button is clicked?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Flush W3TC Cache Programmatically Doesn’t Work’ is closed to new replies.