• Hi
    Can anybody tell me where I’m going wrong with the following code. It performs a meta_query on the event-date field to show only today’s and future events, but it’s returning nothing.

    <?php
    $today = date( "Ymd" );
    $args = array(
    'post_type' => 'event',
    'posts_per_page' => -1,
    'meta_key' => 'wpcf-event-date',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'meta_query' => array(
    array(
    'key' => 'wpcf-event-date',
    'value' => $today,
    'compare' => '>=',
    'type' => 'NUMERIC'
    )
    )
    ); 
    
    $postslist = get_posts($args);
    foreach ($postslist as $post) :
    setup_postdata($post); ?>
    
    // My output goes here
    
    <?php endforeach; ?>

    The “compare” doesn’t seem to fire for “greater than or equal” to today’s date. The date in WP is stored in the same format (Ymd) – I’ve tried “DATE” for the “type” attribute but that doesn’t work either.

    Any help would be much appreciated.

    https://www.ads-software.com/plugins/types/

Viewing 1 replies (of 1 total)
  • Hi mussy, if I understand this correctly, the problem is that $today = date( "Ymd" ); is a formatted string, which you’re trying to compare to a numeric value of the postmeta in the meta_query – 'value' => $today,.

Viewing 1 replies (of 1 total)
  • The topic ‘Show today and beyond for event custom post type’ is closed to new replies.