简体   繁体   中英

How do I query wordpress posts based on comment count and less than one year old?

I have the following code, which returns the posts with the most amount of comments:

$popPosts = new WP_Query();
$popPosts->query('ignore_sticky_posts=1&posts_per_page='.$posts.'&orderby=comment_count'); 

I need to alter it so that it doesn't return any articles that are more than a year old. Can anybody offer a solution?

Thanks!

Something like this might help:

$args = array(
    'date_query' => array(
        array(
            'column' => 'post_date_gmt',
            'after' => '1 year ago',
        )
    ),
    'posts_per_page' => $posts,
    'ignore_sticky_posts' => 1,
    'orderby' => 'comment_count'
);
$query = new WP_Query( $args );

As seen here: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters (under "Date Parameters")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM