Support » Plugins and Hacks » Purge Custom Post Types

Purge Custom Post Types

  • 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 ) )
    	$w3_cacheflush = w3_instance('W3_CacheFlush');


Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Frederick Townes


    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

    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 (get_post_type($post_id) != 'vacancies')
        $plugin_totalcacheadmin = & w3_instance('W3_Plugin_TotalCacheAdmin');

    When I check ‘archives’ in the Purge Policies, this will also clear the archives for all custom post types?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Purge Custom Post Types’ is closed to new replies.