I am trying to execute the following code:
$today123 = date('Ymd');
$args123 = array (
'post_type' => 'myType',
'meta_query' => array(
'relation'=>'AND',
array(
'key' => 'date',//this is a custom field, not the std 'date' field of wp
'compare' => '>=',
'value' => $today123,
)
),
'posts_per_page' => 10,
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$variable=new WP_Query($args123);
to filter my custom post type based on a custom field, i use the query in a loop as intended and i check out the output with a couple of var_export
the query is completly ignoring my meta_query (i tried deleting the orderby but even without it, the metaquery simply isn't beign applied)
so i tempered a little with the code and checkout various outcomes in various situation and i found out something,
if use
'compare' => '>=',
it gets ignored, and it returns all the posts even the ones that doesn't have a
'meta_date' >= date('Ymd')
but if i use the exact same code, putting
'compare' => '<=',
magically the filter gets applied and working as i would expect the <= compare to work.
I may be missing something here, i need to retrieve the 'myType' posts that have a value of meta_date greater or equal to date('Ymd') and sort them by the meta_data in a ASC order...
Why compare '<=' works and compare '>=' doesn't? How can i achieve my desidered result?
EDIT:
"Funny" discovery: if i don't orderby and order, compare >= works...
var_dump($variable)
orderby
tometa_value
and notmeta_value_num
?