Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Set post views count using post meta

/*
 * Set post views count using post meta
 */
function setPostViews($postID) {
    $countKey = 'post_views_count';
    $count = get_post_meta($postID, $countKey, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $countKey);
        add_post_meta($postID, $countKey, '0');
    }else{
        $count++;
        update_post_meta($postID, $countKey, $count);
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Set #post #views #count #post #meta
ADD COMMENT
Topic
Name
1+8 =