How to exclude “set_post_views” function from caching
-
Hey there,
This plugin works fine with my theme but i used below code to set and get post’s views:<?php set_post_views (get_the_ID()); ?> <?php echo get_post_views (get_the_ID()); ?>and Function is:
function set_post_views( $postID ) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; // delete old 'post_views_count' value. delete_post_meta( $postID, $count_key ); // add new 'post_views_count' value. add_post_meta( $postID, $count_key, '0' ); } else { $count++; // update old 'post_views_count' value. update_post_meta( $postID, $count_key, $count ); } } function get_post_views( $postID ) { $count_key = 'post_views_count'; $count = get_post_meta( $postID, $count_key, true ); if($count=='') { // delete old 'post_views_count' value. delete_post_meta( $postID, $count_key ); // add new 'post_views_count' value. add_post_meta( $postID, $count_key, '0' ); return "0"; } return $count.''; }This code can update post’s views for every refresh and this is what i need. But Hummingbird cache caused this functions stop from working and views won’t increase anymore.
Is there any way to exclude this function from caching and count again every refresh and visits even beside of caching?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘How to exclude “set_post_views” function from caching’ is closed to new replies.