是的,只需在调用之前添加一个筛选器,然后删除它
function filter_where_wpa89154($where = \'\') {
//posts in the last 30 days
$where .= " AND post_date > \'" . date(\'Y-m-d\', strtotime(\'-30 days\')) . "\'";
return $where;
}
add_filter(\'posts_where\', \'filter_where_wpa89154\');
$args = array(
\'posts_per_page\' => 5,
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'suppress_filters\' => false
);
$posts = get_posts($args);
remove_filter(\'posts_where\', \'filter_where_wpa89154\');
请注意
\'suppress_filters\' => false
这就是为什么
get_posts