使用 ACF 查询自定义帖子类型 今天>日期



我使用的是PHP 7.3.5and wordpress 5.2.x

我有以下自定义的帖子类型:

register_post_type('Calendar-Events', array(
'supports' => array('title', 'editor', 'thumbnail', 'custom-fields', 'excerpt', 'comments', 'revisions'),
'public' => false,
'show_ui' => true,
'exclude_from_search' => true,
'menu_position' => 5,
'labels' => array(
'name' => 'Calendar Events',
'add_new_item' => 'Add New Calendar Event',
'edit_item' => 'Edit Calendar Event',
'all_items' => 'All Calendar Events',
'singular_name' => 'Calendar Event',
),
'menu_icon' => 'dashicons-calendar-alt',
));

我的帖子类型有一个名为ce_timestamp的自定义字段,它是Date Time Picker,是使用ACF Version 5.8.7创建的。

我正在尝试查询ce_timestamp字段晚于今天的所有帖子。

我尝试了以下方法:

$today = date('d/m/Y');
try {
$args = array(
'post_type' => 'Calendar-Events',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'ce_timestamp',
'value' => $today,
'type' => 'DATE',
'compare' => '>='
)
),
'meta_key' => 'ce_timestamp',
);
$upcomingEvents = new WP_Query($args);
if ( $upcomingEvents->have_posts() ) {
while ( $upcomingEvents->have_posts() ) {
$upcomingEvents->the_post();
// now $query->post is WP_Post Object, use:
// $query->post->ID, $query->post->post_title, etc.
}
}
wp_reset_postdata();
} catch (Exception $ex) {
error_log($ex);
}

然而,我一无所获。

有什么建议我做错了什么吗?

感谢您的回复!

$today= date('Ymd');
$args = array(
'post_type' => 'Calendar-Events',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'ce_timestamp',
'compare' => '>=',
'value' => $today,
),
),
);
$upcomingEvents= new WP_Query( $args );

试试这个

最新更新