I'm having some trouble getting an arguments array to sort an event list by the date in Wordpress. I've found several suggested solutions here on Stack Overflow and elsewhere, but none of the solutions seem to work after lots of trial and error.
It's nothing fancy, and it should be a lot easier than this. Maybe it is easier and I'm just overthinking it? Any help is greatly appreciated.
I've got a custom Date Field inside the Post using the plugin http://www.advancedcustomfields.com, field name in the database is "event_date".
I've tried the following in various forms:
$args = array(
'post_status' => 'publish',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => 6,
'paged' => $paged,
'post__not_in' => $exclude_array
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
$default_excerpt_length = 250;
And:
$args = array(
'post_status' => 'publish',
'meta_key' => 'event_date',
'meta_value_num' => time(),
'meta_compare' => '>=',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => 6,
'paged' => $paged,
'post__not_in' => $exclude_array
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
$default_excerpt_length = 250;
And:
$today = date('Y-m-d');
query_posts(array(
'post_type' => 'events',
'posts_per_page' => 6,
'paged' => $paged,
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'event_date',
'meta-value' => $value,
'value' => $today,
'compare' => '>=',
'type' => 'CHAR'
)
)
));