我编写了一个带有日期范围的WP\\u查询。
$args = array(
\'date_query\' => array(
array(
\'column\' => \'post_date_gmt\',
\'after\' => array(\'year\' => $after[0], \'month\' => $after[1], \'day\' => $after[2])
),
array (
\'column\' => \'post_date_gmt\',
\'before\' => array(\'year\' => $before[0], \'month\' => $before[1], \'day\' => $before[2])
)
),
\'posts_per_page\' => -1,
\'inclusive\' => false,
);
$posts = new WP_Query( $args );
当我输出sql并在phpmyadmin中运行它时,它可以很好地工作。SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND ( wp_posts.post_date_gmt > \'2015-01-11 23:59:59\'
AND wp_posts.post_date_gmt < \'2015-01-17 00:00:00\' ) AND wp_posts.post_type = \'post\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\')
ORDER BY wp_posts.post_date DESC
然而,循环打印出更多的帖子if ( $posts->have_posts() ) :
while ( $posts->have_posts() ) : $posts->the_post();
我尝试过使用重置循环功能,但没有成功。我做错了什么。这是在一个试图模拟存档的页面模板中。谢谢
克里斯