set post views count using post meta

Solutions on MaxInterview for set post views count using post meta by the best coders in the world

showing results for - "set post views count using post meta"
Alina
26 Sep 2017
1/*
2 * Set post views count using post meta
3 */
4function setPostViews($postID) {
5    $countKey = 'post_views_count';
6    $count = get_post_meta($postID, $countKey, true);
7    if($count==''){
8        $count = 0;
9        delete_post_meta($postID, $countKey);
10        add_post_meta($postID, $countKey, '0');
11    }else{
12        $count++;
13        update_post_meta($postID, $countKey, $count);
14    }
15}
16