Support » Plugin: WP-Optimize - Cache, Clean, Compress. » Option to disable cache for specific post types

  • Resolved apedog

    (@apedog)


    hi,
    Is there a way to disable caching for specific post types (including custom post types)? Either through the WP user/Admin or programatically? Excluding URLs might not work for post types that don’t have a front slug.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    You can exclude taxonomies and terms:

    add_action('wp',
    	function() {
    		if (has_term( array( 'term' ), 'new-taxonomy' ) && !defined('DONOTCACHEPAGE')) {
    			define('DONOTCACHEPAGE', true);
    		}
    	}
    );

    https://wordpress.org/support/topic/exclude-a-custom-taxonomy-from-caching/#post-11998516

    Thread Starter apedog

    (@apedog)

    oh thanks.
    that’s workable.

    Plugin Support Marc Lacroix

    (@marcusig)

    Hi @apedog,

    You also change the condition has_term( array( 'term' ), 'new-taxonomy' ) && !defined('DONOTCACHEPAGE') to anything you need, like 'my-cpt' == $post->post_type && !defined('DONOTCACHEPAGE') (pseudo code).

    e.g.

    add_action('wp',
    	function() {
    		global $post;
    		if ('my-cpt' == $post->post_type && !defined('DONOTCACHEPAGE')) {
    			define('DONOTCACHEPAGE', true);
    		}
    	}
    );
    

    (I haven’t tested this code, so it might need tweaking).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Option to disable cache for specific post types’ is closed to new replies.