Site logo

Archived topic

Display most visited posts WP_Query

1 reply · Started by Hilton on July 24, 2020

Viewing posts 1–2 of 2

Hello,

I currently use a WP_Query to display the most recent articles using a shortcode.

The WP_Query is this one:

$the_query = new WP_Query( array(
'cat' => $category->term_id,
'posts_per_page' => 5,
'order' => 'desc',
'orderby' => 'modified'
)

I would like to know if, to display the most visited articles instead of the most recent ones, I could use this WP_Query here:

$the_query = new WP_Query( array(
'cat' => $category->term_id,
'posts_per_page' => 5,
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num'
)

Thanks

This archived topic is closed to new replies.