我正在创建一个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网站上找到的内容中,它应该返回comment_count订购的过去4天的文章。
但它只是向我展示了我的最后4篇文章,我确信我在做一些非常明显的错误,但我不能理解它
我想要的4篇文章与最多的评论在过去的4天内张贴的文章。
有没有人留着我剩下的一点头发
发布于 2012-05-29 16:33:37
感谢@swapnesh,我找到了答案。
我的查询不正确,应该是这样的
$the_query = new WP_Query(array( 'posts_per_page' => 4, 'orderby' => 'comment_count', 'order'=> 'DESC' ));https://stackoverflow.com/questions/10794934
复制相似问题