How to query for most viewed posts and show top 5

View this section of the Codex to learn how to create a custom query:
http://codex.wordpress.org/Class_Reference/WP_Query

Your query will be something like:

$query = new WP_Query( array(
    'meta_key' => 'post_views_count',
    'orderby' => 'meta_value_num',
    'posts_per_page' => 5
) );

By default, the ordering will be highest to lowest, thus giving you the “top” 5.

Leave a Comment