You can pass post id as argument in the views function. Please check following example. An optional argument is passed in the function. If nothing is passed, id is fetched from get_the_ID()
.
if ( !function_exists( 'mvp_post_views' ) ) {
function mvp_post_views( $post_id = '' ){
if ( $post_id ) {
$post_id = absint( $post_id );
} else {
$post_id = get_the_ID();
}
$count_key = 'post_views_count';
$n = get_post_meta($post_id, $count_key, true);
if ($n > 999999999) {
$n_format = number_format($n / 1000000000, 1) . 'B';
} else if ($n > 999999) {
$n_format = number_format($n / 1000000, 1) . 'M';
} else if ($n > 999) {
$n_format = number_format($n / 1000, 1) . 'K';
} else {
$n_format = $n;
}
echo $n_format;
}
}