我需要在一定的时间范围内获得帖子。我正在使用posts_where
滤器
我想指定开始日期和结束日期。这是我使用的函数:
function filter_where( $where = \'\' ) {
$where .= " AND post_date >= \'2012-03-01\' AND post_date =< \'2014-03-01\'";
return $where;
}
此筛选器不返回任何内容。错误必须位于秒附近的任何位置
AND
.
这是我的职责:
number_sold_mottos( $from, $till );
function number_sold_mottos( $from, $till ){
add_filter( \'posts_where\', \'filter_where\' );
$args = array( \'posts_per_page\' => -1, \'post_type\' => \'shop_order\' );
$post_ids = array();
$the_query = new WP_Query( $args );
$last_order_ids = array();
if ( $the_query -> have_posts() ):
while ( $the_query -> have_posts()) :
$the_query -> the_post();
the_title();
endwhile;
endif;
wp_reset_query();
remove_filter( \'posts_where\', \'filter_where\' );
}
function filter_where( $where ) {
$where .= " AND post_date >= \'2012-03-01\' AND post_date =< \'2014-03-01\'";
return $where;
}
欢迎任何帮助。
SO网友:Anjum
不执行空操作$where
函数参数中的变量这就是为什么什么也得不到,因为$where
函数中定义的语句没有日期范围以外的任何查询参数,需要展开$where
像这样。
已编辑:
number_sold_mottos( $from, $till );
function number_sold_mottos( $from, $till ){
add_filter( \'posts_where\', \'filter_where\' );
$args = array( \'posts_per_page\' => -1, \'post_type\' => \'shop_order\' );
$post_ids = array();
$the_query = new WP_Query( $args );
$last_order_ids = array();
if ( $the_query->have_posts() ):
while ( $the_query->have_posts()) :
$the_query->the_post();
the_title();
endwhile;
wp_reset_postdata();
endif;
remove_filter( \'posts_where\', \'filter_where\' );
}
function filter_where( $where ) {
$where .= " AND post_date >= \'2012-03-01\' AND post_date <= \'2014-03-01\'";
return $where;
}