wordpress - 使用 ACF 日期 > 今天查询自定义帖子类型
问题描述
我正在使用PHP 7.3.5
and 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
aDate 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 );
试试这个
推荐阅读
- python-3.x - ODOO_11 onchange message_send
- asp.net - 如何对一对一或一对零关系进行 CRUD 操作?
- openmp - 如何使用openmp为数学函数“exp”生成simd代码?
- c - 对于具有预定义值的变量的行为不同
- javascript - 在页面加载 AngularJS 上使用 opt-group 在下拉列表中显示选定的选项不起作用
- android - Android ONVIF - 尝试从 ONVIF IP 摄像机检索配置文件时出现内部服务器错误
- java - 在 MySQL 中使用印度数字分隔符格式化货币金额
- android-databinding - 如何在 Android 数据绑定中传递空参数
- c# - 箭头键导致 WPF 游戏出现巨大延迟
- c - C 中的 FORWARD_NULL 与 UNINIT 覆盖率错误