$todayDate = date('m/d/Y');
$futureDate = strtotime ( '+7 days' , strtotime ( $todayDate ) ) ;
$futureDate = date ( 'm/d/Y' , $futureDate );
$args = array(
'post_type' => 'events',
'post_status' => 'publish',
'posts_per_page' => -1,
'event_category' => 'events',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $futureDate,
)
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
我想展示下周或下个月即将举行的活动。我有这个args数组,但仍然给我昨天的帖子,而不是按照我想要的方式排序。另外,如何在我的查询中删除昨天的帖子..
答案 0 :(得分:1)
所以,如果你希望你的args限制今天和未来日期之间的事件,那么未来的日期是今天+7天。
因此,您希望修改args以包含具有以下参数的另一个数组。试试这个:
//event_date >= $todayDate
//event_date <= $futureDate
$args = array(
'post_type' => 'events',
'post_status' => 'publish',
'posts_per_page' => -1,
'event_category' => 'events',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $todayDate,
),
array(
'key' => 'event_date',
'compare' => '<=',
'value' => $futureDate,
),
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);