<?php
$cat = get_query_var('cat');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
function filter_where( $where = '' ) {
// posts for March 1 to March 15, 2010
$where .= " AND post_date >= '2010-03-01' AND post_date < '2010-03-16'";
return $where;
}
$args = array(
'cat' => 4,
'posts_per_page' => 30,
'paged' => $paged
);
add_filter( 'posts_where', 'filter_where');
$my_query = new WP_Query($args);
remove_filter( 'posts_where', 'filter_where' );
if ($my_query->have_posts()):
/* Start the Loop */
while ($my_query->have_posts()) : $my_query->the_post();
get_template_part('single', 'bandi');
endwhile;
endif; ?>
这是我的代码。我试图在日期范围内显示特定类别的帖子。如果没有过滤器查询工作正常,则从提供的类别返回帖子。添加过滤器使查询返回帖子在日期范围内,但删除类别ID,并从整个站点查询返回帖子。有什么帮助吗?谢谢