WordPress.org

Forums

W3 Total Cache
Purge Custom Post Types (3 posts)

  1. Modderbaard
    Member
    Posted 3 months ago #

    W3TC does not have a purge policy for custom post types.

    My Problem:
    I have a Custom post type 'vacancy'.
    When the user adds a new vacancy I want the cache to be cleared for vacancy-archives and the home page. I can also live with a compleet cache flush.

    AFAICS W3TC has no hooks for this.

    The function below is ot working. How should I approach this?

    add_action( 'edit_post', 'w3_flush_cpt', 10, 1 );
    add_action( 'delete_post', 'w3_flush_cpt', 10, 1 );
    
    function w3_flush_cpt( $post_id ) {
    	if ( 'vacancy' != get_post_type( $post_id ) )
    		return;
    	$w3_cacheflush = w3_instance('W3_CacheFlush');
    	$w3_cacheflush->pgcache_flush_post($post_id);
    }

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

  2. Frederick Townes
    Member
    Plugin Author

    Posted 3 months ago #

    Custom post types should be handled the same way as default posts/pages. Have you checked the correct Purge Policies on the Page Cache settings page? Front page, archive pages etc.

    You could also try add the archive page to the "Additional pages" textarea under Purge Policy

  3. Modderbaard
    Member
    Posted 3 months ago #

    For now I did it like this.
    This clears the complete bcache, but I can live with that

    add_action( 'save_post', 'w3_flush_cpt', 10, 1 );
    add_action( 'edit_post', 'w3_flush_cpt', 10, 1 );
    add_action( 'delete_post', 'w3_flush_cpt', 10, 1 );
    /**
    * Clear the W3TC cache when vacancies are added, saved or removed
    */
    function w3_flush_cpt( $post_id ) {
    	if(!class_exists('W3_Plugin_TotalCacheAdmin'))
    		return;
    	if (get_post_type($post_id) != 'vacancies')
    		return;
        $plugin_totalcacheadmin = & w3_instance('W3_Plugin_TotalCacheAdmin');
        $plugin_totalcacheadmin->flush_all();
    }

    @Frederick
    When I check 'archives' in the Purge Policies, this will also clear the archives for all custom post types?

Reply

You must log in to post.

About this Plugin

About this Topic