WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] Batch Purge for Selective Pages (6 posts)

  1. Jesse Gardner
    Member
    Posted 2 years ago #

    We've got an automated process that regularly imports videos from Brightcove into our WordPress install as posts. There are several pages across the site where we're featuring these videos within a loop. However, since the site is being cached by W3 Total Cache, I either have to manually purge the page cache for each related page or purge the entire page cache.

    I'd rather not purge the entire page cache as our site is heavily trafficked and we've got several thousand pages. However, clearing the page cache for each page featuring the loop is tedious.

    Is there a function I can pass an array of post id's to have those specific posts purged from the page cache? I'd love to be able to build that into the video import process.

    Thanks!

  2. Jesse Gardner
    Member
    Posted 2 years ago #

    Sorry, I should have read the FAQ's a bit more carefully.

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

  3. Steffi3rd
    Member
    Posted 2 years ago #

    And how to purge archive page. For example /blabla/page/2 ?

  4. Jesse Gardner
    Member
    Posted 2 years ago #

    That's a good question, Steffi3rd. I have a hunch archive pages can't be "cherry picked" for cache purging and that need to get a full page cache purge.

  5. onelife1985
    Member
    Posted 2 years ago #

    @Steffi3rd and @Jesse Gardner what I did was to use the same command for post flush

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

    but instead of adding the post ID I added the category/tag ID and it worked. Why? Because it makes sense it terms of computer programming. So think of it as this command will flush individual items.

    By flushing a category/tag by ID (which is the only way) it flushes the whole category, including /blabla/page/2 etc..

    When I got to the point to ask the same question I looked into the faq and I noticed there are only two methods provided by W3TC to flush the cache. Then I asked my self "how does W3TC flush the categories/tags then..?". I tried it and it simply worked.

  6. archonic
    Member
    Posted 1 year ago #

    but instead of adding the post ID I added the category/tag ID and it worked

    I'm not seeing the same results. I've got this in functions.php and it's working fine (retrieval of categories and such) except it doesn't clear the category page with w3tc_pgcache_flush_post($category->cat_ID).

    /**
     * Flushes out appropriate category pages when a post is updated.
     */
    if(!function_exists('category_cache_flush_on_post')){
    	function category_cache_flush_on_post( $post_id ) {
    		if(function_exists('w3tc_pgcache_flush_post') && !wp_is_post_revision($post_id) ){
    			$cache_message = "The cache for the following categories were cleared: ";
    			foreach( ( get_the_category()) as $category) {
    				w3tc_pgcache_flush_post($category->cat_ID);
    				$cache_message .= $category->cat_name . ", ";
    			}
    			_log($cache_message);
    		}
    	}
    }
    add_filter( 'publish_post', 'category_cache_flush_on_post', 10, 1 );

    Can you post your working code onelife1985?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic