* You are viewing Posts Tagged ‘WordPress’

WordPress Track post views without a plugin using post meta

Add this code into the functions.php of your wordpress theme then follow step 1. and step 2. to display the number of views for each post.
PHP – functions.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 View”;
}
return $count.’ Views';
}
function setPostViews($postID) {
$count_key = ‘post_views_count';
$count = get_post_meta($postID, … Continue Reading