Support

Account

Home Forums General Issues loop with post based on date picker

Solved

loop with post based on date picker

  • Hi,

    This code used to work, but for some reason I can’t get it to work now, basically I want to display the “reports” that are from today and on for the next 5 days…
    I have set the date picker field “date” set to “yymmdd” but still showing old post…

    Ideas?

    <?php
    $today = date("Ymd");
    ?>
    <?php $loop = new WP_Query( array(
    'post_type' => 'report',
    'posts_per_page' => 5,
    'meta_key' => 'date',
    'meta_compare' => '>=',
    'meta_value' => '$today',
    'orderby' => 'meta_value',
    'order' => 'ASC'
    ) );	?>
    
    <?php while ($loop->have_posts()) : $loop->the_post(); ?>
    
    //do stuff
    
    <?php endwhile; ?>
  • this code did the trick

    <?php $today = date("Ymd");?>
    <?php $loop = new WP_Query( array(
    'post_type' => 'reports',
    'posts_per_page' => 5,
    'meta_key' => 'date',
    'meta_compare' => '>=',
    'meta_value' => $today,
    'orderby' => 'meta_value_num',
    'order' => 'ASC'
    ) );	?>
    
    <?php while ($loop->have_posts()) : $loop->the_post(); ?>
    // do stuff
    <?php endwhile; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘loop with post based on date picker’ is closed to new replies.