How to Display Most View Post in the template file?
I need to create most viewed post column in the template file, but based on post view count?
Function File
function wpb_get_post_views($postID){
$count_key = 'wpb_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';
}
Template File
?php
$popularpost = new WP_Query( array( 'posts_per_page' = 4, 'meta_key' = 'wpb_post_views_count',
'orderby' = 'meta_value_num', 'order' = 'DESC' ) );
while ( $popularpost-have_posts() ) : $popularpost-the_post();
the_title();
endwhile;
?