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 array( ‘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() ) : ?> <?php //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.