首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress查询显示X天内评论最多的文章

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

Stack Overflow用户
提问于 2012-05-29 15:40:26
回答 1查看 1.4K关注 0票数 1

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

到目前为止,我有这个

代码语言:javascript
复制
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网站上找到的内容中,它应该返回comment_count订购的过去4天的文章。

但它只是向我展示了我的最后4篇文章,我确信我在做一些非常明显的错误,但我不能理解它

我想要的4篇文章与最多的评论在过去的4天内张贴的文章。

有没有人留着我剩下的一点头发

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-29 16:33:37

感谢@swapnesh,我找到了答案。

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

代码语言:javascript
复制
    $the_query = new WP_Query(array( 'posts_per_page' => 4, 'orderby' => 'comment_count', 'order'=> 'DESC' ));
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10794934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档