• Good day!
    There plugin WP Super Cache, which is necessary to make an exception to cache display. That’s actually a code that I found on the internet for a ban caching time – tested it, it works. I need to somehow push back the code:

    <?php
    define( 'DYNAMIC_OUTPUT_BUFFER_TAG', 'SAPEBLOCK' );
    function dynamic_output_buffer_test( &$cachedata = 0 ) {
        if ( defined( 'DYNAMIC_OB_TEXT' ) )
            return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
        ob_start();
        echo date( 'H:i:s' );
        $text = ob_get_contents();
        ob_end_clean();
    
        if ( $cachedata === 0 )
            define( 'DYNAMIC_OB_TEXT', $text );
        else
            return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
    }
    add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
    
    function dynamic_output_buffer_test_safety( $safety ) {
        if ( defined( 'DYNAMIC_OB_TEXT' ) )
            return 1;
        else
            return 0;
    }
    add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
    ?>

    Here is my code to display the number of views and counting.

    <?php echo getPostViews(get_the_ID()); ?>
    <?php setPostViews(get_the_ID()); ?>

    Here’s the code function that provides the display:

    function getPostViews($postID){
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
            return "0";
        }
    	echo _e('', 'dot-b');
        return $count;
    }
    function setPostViews($postID) {
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            $count = 0;
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
        }else{
            $count++;
            update_post_meta($postID, $count_key, $count);
        }
    }

    https://wordpress.org/plugins/wp-super-cache/

  • The topic ‘Exclude views of caching’ is closed to new replies.