1

I need to change the most popular post widgets with date restrictions.

For an example, how should I get most popular posts(post_views_count) of last 7 days.

original query,

$popularposts = new WP_Query('showposts=10&meta_key=post_views_count&orderby=meta_value_num&order=DESC&ignore_sticky_posts=1')

then I changed that to,

$args = array(
    'date_query' => array( array( 'after' => '-7 days' ) ),  
    'showposts' => 10,
    'ignore_sticky_posts' => 1,
    'meta_key' => 'post_views_count',
    'orderby' => 'meta_value_num',
    'order' => 'DESC'
);
$the_query = new WP_Query( $args );

However it doesn't give any results. How should I achieve this?

Thanks in advance.

2

The correct syntax to get posts from the last week is 1 week ago. Just another note, showposts is replaced in favor of posts_per_page. Apart from that, your query should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.