WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
How to purge specific pages upon Post Publish / Update (4 posts)

  1. aaron.lane
    Member
    Posted 1 year ago #

    Hello,

    We're using a custom loop to display the 10 most recent posts on a page called News & Events and the 3 most recent posts on our home page (home.php).

    How can we implement the following code to purge the cache of our Home and News & Events pages each time a Post is published or updated?

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

    Thanks,
    Aaron

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. ajuliano
    Member
    Posted 1 year ago #

    I would like some help on this issue as well.

    I can't get w3tc_pgcache_flush_post($post_id); to work in my code.

    add_action( 'publish_lucka', 'run_when_lucka_published', 15 );
    
    function run_when_lucka_published( $post_id ) {
    	if ( get_post_type( $post_id ) != 'lucka' )
    		return;
    
    	if ( function_exists('w3tc_pgcache_flush_post') ) {
    		w3tc_pgcache_flush_post( 5864 );
    	}
    }
  3. jumbo
    Member
    Posted 1 year ago #

    In the "Page Cache" settings, there should be a "Purge Policy" section that states "Specify the pages and feeds to purge when posts are created, edited, or comments posted."

    You should check those boxes that you need purged when you update those items.

  4. aaron.lane
    Member
    Posted 1 year ago #

    Jumbo,

    Unfortunately, I am wanting to implement the above code because the pages specified in the "Purge Policy" are not being purged. I suspect is has to do with our Custom Loop.

    Can anyone tell us how to use the above function properly?

    Thanks in advance,
    Aaron

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic