$now = date('Ymd', strtotime("now"));
$future = date('Ymd', strtotime("+24 months"));
$uc_args = array(
'post_type' => 'event',
'meta_query' => array(
'relation' => 'OR',
// check post has end_date and it is between $now and $future
array(
'key' => 'end_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($now, $future),
),
// if no end date check event_date is between $now and $future
array(
'key' => 'event_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($now, $future),
),
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'nopaging' => true,
);
$now = date('Ymd', strtotime("now"));
$future = date('Ymd', strtotime("+24 months"));
$uc_args = array(
'post_type' => 'event',
'meta_query' => array(
'relation' => 'OR',
// check post has end_date and it is between $now and $future
array(
'key' => 'end_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($now, $future),
),
// if no end date check event_date is between $now and $future
array(
'key' => 'event_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($now, $future),
),
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'nopaging' => true,
);
$past = date('Ymd', strtotime("-999 months"));
$now = date('Ymd', strtotime("now"));
$uc_args = array(
'post_type' => 'event',
'meta_query' => array(
'relation' => 'OR',
// check post has end_date and it is between $past and $now
array(
'key' => 'end_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($past, $now),
),
// if no end date check event_date is between $past and $now
array(
'key' => 'event_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($past, $now),
),
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'nopaging' => false,
'posts_per_page' => '8',
);
$past = date('Ymd', strtotime("-999 months"));
$now = date('Ymd', strtotime("now"));
$uc_args = array(
'post_type' => 'event',
'meta_query' => array(
'relation' => 'OR',
// check post has end_date and it is between $past and $now
array(
'key' => 'end_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($past, $now),
),
// if no end date check event_date is between $past and $now
array(
'key' => 'event_date',
'compare' => 'BETWEEN',
'type' => 'NUMERIC',
'value' => array($past, $now),
),
),
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'nopaging' => false,
'posts_per_page' => '8',
);