Get popular post of a week updated based on view count

I have this codes

//Set the parameters / arguments for the query
$popular_post_args = array(

‘meta_key’ => ‘post_views_count’, //meta key currently set
‘orderby’ => ‘meta_value_num’, //orderby currently set
‘order’ => ‘DESC’, //order currently set
‘posts_per_page’ => 10, // show 10 posts
‘date_query’ => array( // date query from after 1 week ago
‘after’ => ‘1 week ago’,

//Initialise the Query and add the arguments
$popular_posts = new WP_Query( $popular_post_args );

//Check if theres posts and add your html divs around it
if ( $popular_posts->have_posts() ) : ?>

//Start the loop
while ( $popular_posts->have_posts() ) : $popular_posts->the_post(); ?>

Which I used to display most viewed post in a week but it fails to achieve what I am looking for. It outputs post in a week but is not able to show 10 post as set. sometimes it shows no post at all meaning there is no popular post in a week. Please is there a way I can modify this code to show most viewed post in a week updating it as newer or older post that falls withing one week gets viewed. For instance if I make a new post and share on Facebook it definitely attracts more views but this code able doesnt update it. So I want something that can update this list of 10 post whenever the views changes. Thanks for your help in advance.

code looks valid… the last commas at the end of your arrays are unnecessary.

You say the query results are erratic?

@m_hutley Thanks for your reply… The issue am facing is this. The code above outputs post from a week or 2 depending on what you set but if set to “1 week ago” for instance, it hardly returns any result. sometimes it returns only one result and this doesnt mean i dont have post made on such timing.
So I am looking for a way to return most viewed post in a week that will update immediately a new or old post that falls within this time range gets more view than other. I want to list this in DESC and it should always generate posts and readjust as posts gets viewed. I was doing something like this with newspaper wordpress theme if I use page builder like wordpress bakery. Thanks once more for your reply.
You can see my my site … those post on trending tab are set in 2 weeks but doesnt update unless until those post that falls were there falls outside the time range.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.