pusatdata icon

Menampilkan Post View tanpa Plugin

pusatdata | PRO | 06/06/17 01:05:20 AM UTC | 0 ⭐ | 384 👁️ | Never ⏰ | []
text |

1.02 KB

|

None

|

0 👍

/

0 👎

http://www.wp-tutorials.com/how-to-count-post-views-without-plugin/
 Paste di 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, $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);
  ============================================
 Jika ditampilkan di LOOP, kodenya:
setPostViews(get_the_ID());
 ============================================
Atau di post-single, pages, dll, kodenya:
<?php echo getPostViews(get_the_ID()); ?>

Comments