$todayDate = date('m/d/Y');
$futureDate = strtotime ( '+7 days' , strtotime ( $todayDate ) ) ;
$futureDate = date ( 'm/d/Y' , $futureDate );
$args = array(
'post_type' => 'events',
'post_status' => 'publish',
'posts_per_page' => -1,
'event_category' => 'events',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $futureDate,
)
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
I want to show the upcoming events for the next week or next month. I have this args array set but still giving me the post of yesterday's and not sorted as how i wanted. Also, how to get rid of yesterday's post in my query..
So if you want your args to limit events that fall between today and the future date, where future date is today +7 days.
Hence you want to modify your args to include another array with the following parameters. Try this:
//event_date >= $todayDate
//event_date <= $futureDate
$args = array(
'post_type' => 'events',
'post_status' => 'publish',
'posts_per_page' => -1,
'event_category' => 'events',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $todayDate,
),
array(
'key' => 'event_date',
'compare' => '<=',
'value' => $futureDate,
),
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);