尝试显示特定日期范围的自定义帖子类型。我只想显示某个月内的帖子。我知道我需要连接到 posts_where 过滤器,但我不知道如何将参数传递给这个函数,因为我需要传递日期范围。
我已经看到很多关于如何更改 WHERE 子句以获取日期范围的示例,但仅限于静态时。我需要执行以下操作:
add_filter('posts_where', 'my_custom_where', '', '04/2011'); //pass my date to the filter
function my_custom_where( $where = '' ) {
//figure range
$range = array(
'start' => $date . '-1',
'end' => $date . '-' . cal_days_in_month(CAL_GREGORIAN, date('m', $date), date('Y', $date))
);
$where .= " AND post_date ....."; //build where with date range
return $where;
}
希望这是有道理的。任何帮助,将不胜感激。