I am using PHP 7.3.5
and wordpress 5.2.x
.
I have the following custom post type:
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',
));
My post type has a custom field that is called ce_timestamp
which is a Date Time Picker
and was created using ACF Version 5.8.7
.
I am trying to query all posts where the ce_timestamp
field is later than today.
I tried the following:
$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);
}
However, I get nothing back.
Any suggestions what I am doing wrong?
I appreciate your replies!
I am using PHP 7.3.5
and wordpress 5.2.x
.
I have the following custom post type:
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',
));
My post type has a custom field that is called ce_timestamp
which is a Date Time Picker
and was created using ACF Version 5.8.7
.
I am trying to query all posts where the ce_timestamp
field is later than today.
I tried the following:
$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);
}
However, I get nothing back.
Any suggestions what I am doing wrong?
I appreciate your replies!
Share Improve this question asked Nov 16, 2019 at 7:08 Carol.KarCarol.Kar 3771 gold badge8 silver badges18 bronze badges1 Answer
Reset to default 0Please check the ce_timestamp meta_key row in postmeta table. And make sure you have the valid dateformat as meta value.