popular post weekly and monthly

i want to display popular posts for 1 week ago and 1 month ago.these are codes that i used but these don't work correctly for 1 week ago

ul

    ?php
    $week = date('W');
    $year = date('Y');
    query_posts('meta_key=post_views_countcat='.$link1.'posts_per_page=9orderby=meta_value_numorder=DESCyear=' . $year . 'weeknum=' . $week);

    while (have_posts()): the_post(); ?

    li
    h2a href="?php the_permalink(); ?" target="_blank"?php the_title(); ?/a/h2
div style="display:?php echo $display;?" class="tooltiptext hidden-xs"?php the_excerpt(); ?/div
/li
    ?php
    endwhile;
    wp_reset_query();
    ?

    /ul

for 1 month ago

 ul

    ?php
    $month = date('m');
    $year = date('Y');
    query_posts('meta_key=post_views_countcat='.$link1.'posts_per_page=9orderby=meta_value_numorder=DESCyear=' . $year . 'monthnum=' . $month);

    while (have_posts()): the_post(); ?

       li
    h2a href="?php the_permalink(); ?" target="_blank"?php the_title(); ?/a/h2
div style="display:?php echo $display;?" class="tooltiptext hidden-xs"?php the_excerpt(); ?/div
/li
    ?php
    endwhile;
    wp_reset_query();
    ?

    /ul

Topic popular-posts loop query-posts Wordpress

Category Web


These $args is what you need and you may also use that in query_posts();

$args = array(
        'post_type'         => array( 'post' ),
        'post_status'       => 'publish',
        'posts_per_page'    => 9,
        'cat'               => $link1, // try better variable name

        'meta_key' => 'post_views_count',
        'orderby' => 'meta_value_num',
        'order' => 'DESC',          

        'date_query' => array(
        array(
          'after' => '1 months ago',
        ),
        )   
);

$r = null;
$r = new WP_Query($args);
// do something with $r = result
wp_reset_postdata();

I provided you some other way than query_posts(). BTW, I like you used wp_reset_query(); at the end.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.