I need to display the upcoming events for next 30 Days and sort the same based on custom date field.
Below is the code I am using right now but not got any success in hiding old Events and restricting events to 30 Days.
<?php
$todayDate = date('d F, Y');
$futureDate = strtotime ( '+30 days' , strtotime ( $todayDate ) ) ;
$futureDate = date ( 'd F, Y' , $futureDate );
$eventsOpt = array(
'post_type' => 'ptype_events',
'posts_per_page' => -1,
'meta_key' => 'ptype_event_date',
'meta_compare' => '>=',
//'meta_value' => $todayDate,
'orderby' => 'meta_value',
'order' => 'ASC',
);
$events_query = new WP_Query($eventsOpt);
?>
<div class="eventsPosts">
<?php while ($events_query->have_posts()) : $events_query->the_post();
$date = get_post_meta($post->ID, 'ptype_event_date', true);
?>
<div class="eventsPost clearfix">
<h3 class="title">
<?php the_title()?>
</h3>
Date: <?php echo $date ?> </div>
<?php endwhile; ?>
<?php wp_reset_query() ?>
</div>
Note: Date saved in database is in this format date('d F, Y')
and I cannot change it to timestamp while saving because creating meta-fields using a plugin.
Please help me out.
Regards