amritansh
9/26/2017 - 5:44 AM

This function returns the post count views of a posttype

This function returns the post count views of a posttype

/*
 * This function returns the post count views of a posttype
 */
getPostViews($postID);

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";
    } elseif ($count == 1) {
        return "1 View";
    }
    return $count . ' Views';
}