Skip to content

Instantly share code, notes, and snippets.

@bipinmilan
Created September 28, 2018 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bipinmilan/a9ad95f86dbfee93e17ef62c1c21aa8b to your computer and use it in GitHub Desktop.
Save bipinmilan/a9ad95f86dbfee93e17ef62c1c21aa8b to your computer and use it in GitHub Desktop.
/*view counter code */
function pp_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 pp_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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment