Reset Popular post query?

If you’re ok resetting it weekly – as in have views start from 0 every Monday – rather than trying to show the most read in the last 7 days, then the simplest change would be to have a different meta key for every week of the year. Then when you query the posts, you just query the view count for the current week of the year:

You can do this by just changing this:

$countKey = 'post_views_count';

To this:

$countKey = 'post_views_count_' . date( 'YW' );

date( 'YW' ) will give you a number like 201831, which represents the 31st week of 2018, so each week will get its own meta key like post_views_count_201831.

Then when you query the posts, change:

'meta_key' => 'post_views_count',

To use the meta key for the current week:

'meta_key' => 'post_views_count_' . date( 'YW' ),

This does mean that when the week switches over you’ll briefly have no posts with views, since the count has started over. One thing you could do is change the query so that for 1 day it will continue to show the popular posts from the previous week, while still counting views for the current week:

'meta_key' => 'post_views_count_' . date( 'YW', strtotime( '-1 day' ) ),