Support » Plugin: Cache Enabler - WordPress Cache » How to exclude CPT Archive from cache

  • Resolved derweili

    (@derweili)


    I would like to disable caching for a specific custom post type archive.

    On the Plugins Settings page I can only define Posts IDs but archive pages don’t have an ID.

    On you supports page I read it could be solved by defining the constant “DONOTCACHEPAGE” and setting it to true.

    Unfortunately this does not work for me.

    Where do I have to set this constant.

    I tried this:

    function heilbronn_disable_events_caching(){
      global $post;
    
      // check if we are on events archive page
      if( is_post_type_archive( 'tribe_events' ) ){
    
        // set do not cache constant
        if( ! defined( 'DONOTCACHEPAGE' ) ){
          // wp_die('Set to not cache.');
          define( 'DONOTCACHEPAGE', true );
        }
    
      }
    
    }
    add_action('wp_head', 'heilbronn_disable_events_caching');
Viewing 4 replies - 1 through 4 (of 4 total)
  • The DONOTCACHEPAGE constant should work when defined properly in your functions.php file. Have you tried clearing your cookies and testing while logged out?

    Hopefully you got this sorted by now. I’ve been spending a while on this too trying different hooks and I got this working by adding the function to the ‘wp’ hook. Seems other hooks were too early for $post to be available or too late that the plugin has already kicked in.

    Plugin Author keycdn

    (@keycdn)

    You can also use the bypass_cache filter to bypass the cache.

    I’m asking for help from the author of the plugin (@keycdn).
    I want that this code wasn’t cached:

    I want to prevent caching of a fragment of a code in sidebar.php or sidebar.php completely. I have found information about the DONOTCACHEPAGE function. But I don’t understand as to make it.
    I have added this code to sidebar.php.
    define(‘DONOTCACHEPAGE’, true);

    <?php
    define( ‘DONOTCACHEPAGE’, true );
    $o[‘charset’] = “UTF-8″;
    if (!defined(‘_SAPE_USER’)){
    define(‘_SAPE_USER’, ”);}
    require_once($_SERVER[‘DOCUMENT_ROOT’].’/’._SAPE_USER.’/sape.php’);
    echo “<!–check code–>”;
    $o[‘force_show_code’] = true;
    $sape = new SAPE_client($o);
    echo $sape->return_links();
    unset($o);
    echo “<!–check code–>”;
    ?>

    But it doesn’t work. What do I have to make?

    This code in /wp-content/plugins/cache-enabler/inc/cache_enabler.class.php:

    // DONOTCACHEPAGE check e.g. woocommerce
    if ( defined(‘DONOTCACHEPAGE’) && DONOTCACHEPAGE ) {
    return true;
    }

    or this

    // bypass cache hook
    if ( apply_filters(‘bypass_cache’, false) ) {
    return true;
    }

    Do I need to duplicate this in functions.php or not?
    wp-content/themes/videozoom4/functions.php

    Unfortunately this is difficult for me. If I use bypass cache hook – which code should I use?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to exclude CPT Archive from cache’ is closed to new replies.