How to query for most viewed posts and show top 5

Here is how I am getting the views for one post:

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";
        }
        return $count.' Views';
    }

Let’s say I want to find the most viewed posts from 5,000 posts and I want to show the top 5 most viewed posts.

Read More

How can I make a query to achieve this?

Related posts

Leave a Reply

2 comments