Show the most popular post per week

Okay, so here is the complete query for displaying popular posts of current week. I am using meta_query to limit query results within current week only.

It will get all posts from current week and then sort them by post views count added by custom field wpb_post_views_count that you used in your question.

// Current week's popular posts

$query_args = array(
    'post_type' => 'post',
    'date_query' => array(
        array(
            'year' => date( 'Y' ),
            'week' => date( 'W' ),
        ),
    ),
    'meta_key' => 'wpb_post_views_count',
    'orderby' => 'meta_value_num',
    'ignore_sticky_posts' => 1,
    'posts_per_page' => '-1',
);

$my_query = new WP_Query( $query_args );

if ( $my_query->have_posts() ) :
    while ( $my_query->have_posts() ) : $my_query->the_post();

        // add your loop content here.

    endwhile;
endif;

wp_reset_postdata();

Leave a Comment