• Resolved Jesse Gardner

    (@plasticmind)


    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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jesse Gardner

    (@plasticmind)

    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); }

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

    Thread Starter Jesse Gardner

    (@plasticmind)

    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.

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

    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Batch Purge for Selective Pages’ is closed to new replies.