我有以下代码用于在两个特定日期之间显示帖子:
$s = \'2011-10-23\';
$e = \'2011-11-17\';
function filter_where($where = \'\') {
$where .= \' AND post_date >= $s AND post_date <= $e\';
return $where;
}
add_filter(\'posts_where\', \'filter_where\');
query_posts($query_string);
但在改变这一点之前,这是行不通的:
function filter_where($where = \'\') {
$where .= \' AND post_date >= \'2011-10-23\' AND post_date <= \'2011-11-17\'\';
return $where;
}
add_filter(\'posts_where\', \'filter_where\');
query_posts($query_string);
第一个代码有什么问题?
最合适的回答,由SO网友:Stephen Harris 整理而成
我认为这是因为SQL语句需要引号内的日期。尝试
$where .= " AND post_date >= \'$s\' AND post_date <= \'$e\'";
这应该行得通,否则,试试看
$where .= " AND post_date >= \'".$s."\' AND post_date <= \'".$e."\'";