1

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!

1 Answer 1

0

Please check the ce_timestamp meta_key row in postmeta table. And make sure you have the valid dateformat as meta value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.