我创建了一个名为" Events"的自定义帖子类型。一个自定义字段是事件的日期,我需要根据此日期查询帖子,并仅显示未来事件。我已经接近了,但似乎无法弄清楚如何将过滤器与我已编写过的代码集成在一起。这是我的代码。感谢,
$today = date('dd-MM-yy');
$args = array(
'post_type' => 'events',
'posts_per_page' => 2,
'meta_key' => 'events_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_value_num' => $today,
'meta_compare' => '>'
);
$events = new WP_Query( $args );
答案 0 :(得分:0)
试试这个
$today = date('dd-MM-yy');
$args = array(
'post_type' => 'events',
'posts_per_page' => 2,
'meta_key' => 'events_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'events_date',
'value' => $today,
'compare' => '>',
)
)
);
$events = new WP_Query( $args );