Title: [Plugin: WP-PostViews] Does Postviews work with Super Cache
Last modified: August 20, 2016

---

# [Plugin: WP-PostViews] Does Postviews work with Super Cache

 *  [jeffutogo](https://wordpress.org/support/users/jeffutogo/)
 * (@jeffutogo)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-wp-postviews-does-postviews-work-with-super-cache/)
 * Hey, I found that the postviews does not increase as before, after I installed
   WP Super Cache.
 * Does it work with Super Cache? Thanks!
 * [http://wordpress.org/extend/plugins/wp-postviews/](http://wordpress.org/extend/plugins/wp-postviews/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [hakaner](https://wordpress.org/support/users/kazancexpert/)
 * (@kazancexpert)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-wp-postviews-does-postviews-work-with-super-cache/#post-2681124)
 * Yes it’s working, but not displaying real time counts on posts before the cleaning
   cache. So, it’s counting in background with super cache. I hope, author adds 
   a feature in future versions to resolve this issue.
 *  [Amon](https://wordpress.org/support/users/amon-yao/)
 * (@amon-yao)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-postviews-does-postviews-work-with-super-cache/#post-2681214)
 * Here is some change to support WP Super Cache.
    WP-PostViews 1.62
 *     ```
       function process_postviews() {
       	//...
       		//...
       			if($should_count) {
       				global $cache_enabled; //WP Super Cache enabled or not
       				if(defined('WP_CACHE') && WP_CACHE && $cache_enabled) {
       					echo "\n".'<!-- Start Of Script Generated By WP-PostViews -->'."\n";
       					//...
       				} else {
       					//...
       				}
       			}
       		//...
       	//...
       }
   
       function add_postviews_column($defaults) {
           $defaults['views'] = __('Views', 'wp-postviews');
           return $defaults;
       }
   
       //AJAX get post views
       add_action( 'wp_ajax_postviews_get', 'postviews_get' );
       add_action( 'wp_ajax_nopriv_postviews_get', 'postviews_get' );
       function postviews_get() {
       	if ( !empty( $_GET['postviews_id'] ) ) {
       		$post_id = intval( $_GET['postviews_id'] );
       		if ( $post_id > 0 ) {
       			$views_options = get_option( 'views_options' );
       			$post_views = get_post_custom( $post_id );
       			$output = str_replace( '%VIEW_COUNT%', number_format_i18n( intval( $post_views['views'][0] ) ), $views_options['template'] );
       			$output = apply_filters( 'the_views', $output );
       			echo $output;
       		}
       	}
       	exit();
       }
   
       //the_views support WP Super Cache via AJAX
       function the_views( $display = true, $prefix = '', $postfix = '', $always = false ) {
       	$output = '';
       	$views_options = get_option( 'views_options' );
       	if ( $always || should_views_be_displayed( $views_options ) ) {
       		global $cache_enabled;
       		if ( defined( 'WP_CACHE' ) && WP_CACHE && $cache_enabled ) {
       			global $post;
       			if ( is_int( $post ) ) {
       				$post = get_post( $post );
       			}
       			$id = intval( $post->ID );
   
       			wp_print_scripts( 'jquery' );
       			$output = "\n" . '<!-- Start Of Script WP-PostViews Get Action -->' . "\n";
       			$output .= '<font id="views_' . $id . '">&nbsp;</font>' . "\n";
       			$output .= '<script type="text/javascript">' . "\n";
       			$output .= '/* <![CDATA[ */' . "\n";
       			$output .= "jQuery.ajax({type:'GET',url:'" . admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ) . "',data:'postviews_id=" . $id . "&action=postviews_get',cache:false,complete:function(jqXHR,textStatus){var obj=jQuery('#views_" . $id . "');obj.before('" . $prefix . "'+jqXHR.responseText+'" . $postfix . "');obj.remove();}});\n";
       			$output .= '/* ]]> */' . "\n";
       			$output .= '</script>' . "\n";
       			$output .= '<!-- End Of Script WP-PostViews Get Action -->' . "\n";
       		} else {
       			$output = $prefix . str_replace( '%VIEW_COUNT%', number_format_i18n( intval( post_custom( 'views' ) ) ), $views_options['template'] ) . $postfix;
       			$output = apply_filters( 'the_views', $output );
       		}
       	}
       	if ( $display ) {
       		echo $output;
       		return '';
       	} else {
       		return $output;
       	}
       }
       ```
   
 *  [D J](https://wordpress.org/support/users/wwwpornolatinonet/)
 * (@wwwpornolatinonet)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-postviews-does-postviews-work-with-super-cache/#post-2681215)
 * The code above works, but it is recommendable to be used only in single post.
 * I tried it on a grid template with 50 posts and the website loaded in 30 seconds.
 * Can you come up with a code that if a post is visited then reload the cache for
   that post.
 *  [Amon](https://wordpress.org/support/users/amon-yao/)
 * (@amon-yao)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-postviews-does-postviews-work-with-super-cache/#post-2681216)
 * if a post is visited then reload the cache for that post?
 * I am sorry, You may get contact with the plugin author(if you can, or someone
   else known how WP Super Cache works), to solve this problem.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[Plugin: WP-PostViews] Does Postviews work with Super Cache’ is closed
to new replies.

 * ![](https://ps.w.org/wp-postviews/assets/icon.svg?rev=978002)
 * [WP-PostViews](https://wordpress.org/plugins/wp-postviews/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-postviews/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-postviews/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-postviews/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-postviews/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-postviews/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [Amon](https://wordpress.org/support/users/amon-yao/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-postviews-does-postviews-work-with-super-cache/#post-2681216)
 * Status: not resolved