WordPress count* total views of posts !

count total views post, total post view in wp

Sometime we want to check the total views of the particular post… so here is the solution by using of this code you can check how many times your post is viewed.

  1.  Add this to theme Function.php file

function wpb_set_post_views($postID) {
$count_key = 'wpb_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);
}
}

2.  This one also into Function.php file

function wpb_get_post_views($postID){
$count_key = 'wpb_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 View";
}
return $count.' Views';
}

3. Then put this code to Single.php

<?php wpb_set_post_views(get_the_ID()); ?>

4.  And then put this code where you want to show post count..

<?php echo wpb_get_post_views(get_the_ID()); ?>

5. Thats it  🙂

You can download the full code of Plugin here… after activating this plugin you need to follow just last 2 steps and also you will see the instruction area at the back-end like this..

post-view-count

Download

 

 

If this help you then.. Can you buy a Cup of Coffee for me by nst webcreation paypal--OR-- nst webcreation blog coffee cup

Published by

NST

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Chat