尝试显示特定日期范围的自定义帖子类型.我想仅在某个月内展示帖子.我知道我需要挂钩到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;
}
Run Code Online (Sandbox Code Playgroud)
希望有道理.任何帮助,将不胜感激.