WordPress查询显示X天内评论最多的文章


Wordpress query to display most commented articles over X days

我正在创建一个wordpress小部件来显示过去4天内评论最多的文章。

到目前为止我有这个

global $wpdb;
global $pagepost;

function filter_where( $where = '' ) {
    // posts in the last 4 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-4 days')) . "'";
    return $where;
}
add_filter( 'posts_where', 'filter_where' );
$the_query = new WP_Query( 'posts_per_page=4;orderby=comment_count' );
remove_filter( 'posts_where', 'filter_where' );
?>
    <ul>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post();
    echo "<li>";
    echo "<a href='".get_permalink()."' class='linkTitle'>";
    echo get_the_title();
    echo "</a>";
    woo_post_meta(); 
    echo "<div class='fix'>";
    echo "</li>";   
 endwhile;
    echo "</ul>";
wp_reset_postdata();

从我在wordpress网站上找到的内容来看,应该返回过去4天按comment_count订购的文章

但它只是向我展示了我最近的 4 篇文章,我确定我在这里做错了一些非常明显的事情,但我无法理解

我想要过去 4 天内发布文章评论最多的 4 篇文章。

有人请保存我剩下的一点头发

多亏了@swapnesh我找到了答案。

我的查询不正确,应该是这样的

    $the_query = new WP_Query(array( 'posts_per_page' => 4, 'orderby' => 'comment_count', 'order'=> 'DESC' ));

$querystr = "从 $wpdb->帖子中选择 $wpdb->帖子*,其中 1=1 和 $wpdb->posts.post_status = "发布",$wpdb->posts.post_type = "发布" 按$wpdb->posts.comment_count DESC 排序'";

使用此自定义查询

$pageposts = $wpdb->get_results($querystr, 对象);回声";

print_r($pageposts); 回声";