我正在使用需要按特定日期范围过滤的 wordpress WP_Query 循环。
因此,我设置了以下过滤器以显示超过 10 天的所有帖子:
//Create a filter that only shows posts for a certain time frame
function restrict_posts_by_date_10( $where = '' ) {
global $wpdb;
$where .= " AND post_date <= '" . date('Y-m-d', strtotime('-10 days')) . "'";
return $where;
}
add_filter( 'posts_where', 'restrict_posts_by_date_10' );
出于测试目的,我不能等待几天才能触发其余的动作,所以我想将其设置为 2 分钟。但是,以下不起作用
//Create a filter that only shows posts for a certain time frame
function restrict_posts_by_date_10( $where = '' ) {
global $wpdb;
$where .= " AND post_date <= '" . date('Y-m-d', strtotime('-2 minutes')) . "'";
return $where;
}
add_filter( 'posts_where', 'restrict_posts_by_date_10' );
任何想法都会很棒。
干杯