This is the piece of code I use to get event posts whom date metadata is newer than today :
<?php
query_posts( array(
'post_type' => 'concerts',
'meta_key' => 'numericdate',
'posts_per_page' => -1,
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'numericdate',
'value' => date('dmY'),
'compare' => '>=',
'type' => 'date'
)
)
) );
if (have_posts()) : ?>
This returned no results.
The “numericdate” field contains a “ddmmyyyy” string, so I expected comparing with a “dmY” today date value will work. I was wrong. Or there is some mistake in the code above.
Thanks for your help !
I have exact the same problem here, except i use the std. post type (post) and a category in my query. everything works except the sort order.
$d = date("Y-m-d");
$args = array(
'post_type' => 'post',
'category_name' => 'events',
'post_status' => 'publish,draft,pending,future,private', // just for me
'meta_key' => 'event_start',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'event_start',
'value' => $d,
'type' => 'date',
'compare' => '>'
)
)
);
But my posts get sorted by String-Comparison nonetheless. What did i do wrong?
Well after a little trial and error i found out that instead of ‘meta_value_num’ i should’ve used ‘meta_value’:
$d = date("Y-m-d");
$args = array(
'post_type' => 'post',
'category_name' => 'events',
'post_status' => 'publish,draft,pending,future,private',
'meta_key' => 'event_start',
'orderby' => 'meta_value',
'order' => 'ASC',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'event_start',
'value' => $d,
'type' => 'date',
'compare' => '>'
)
)
);