How to not cache a php code function?
-
Hello,
The greatest plugin from all others i used. But i use a litle code for showing the page views (counter) wich not working right with the wp super cache.
i.e.After 3 hour that a post is published the views counter shows still 0 or 5, and this is not normal. I have more views and i lost the counts.In the plugin settings i use MOD_REWRITE.
The php code is:
<?php 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"; } 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); } } // Remove issues with prefetching adding extra views remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); ?>
<?php echo getPostViews(get_the_ID()); ?>
<?php setPostViews(get_the_ID()); ?>
Is there any solution to work properly this system?
Thank you.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to not cache a php code function?’ is closed to new replies.