meta_query of unix timestamp to custom field
I have a custom field that holds a unix timestamp, and I’ve verified that the data in it is proper.
In my code I’m trying to compare that timestamp against $now, where $now is php’s time(); $now is also holding valid data.
I wanted to get posts where $now is less than my field. I’m using this:
$args = array(
‘post_type’ => ‘closings’
,’posts_per_page’ => 1000
,’meta_query’ => array(
‘key’ => ‘date_time’,
‘value’ => $now,
‘compare’ => ‘<=’,
‘type’ => ‘NUMERIC’
I’m not getting any results out of it. I tried with DATETIME instead of NUMERIC, and I tried reversing my comparison operator.
The docs aren’t clear how the comparison values are ordered. For my code above is it saying ‘date_time <= $now’ or ‘$now <= date_time’ ?
Am I using the wrong type?
I think I figured out part of it, but not how to fix it. I forgot that date_time is part of an array that looks like this:
Array ( [date_value] => Array (  => 1307736000 ) [_edit_lock] => Array (  => 1307719655:1 ) [_edit_last] => Array (  => 1 ) )
However, this still doesn’t work:
Array ( [post_type] => closings [posts_per_page] => 1000 [meta_query] => Array (  => Array ( [key] => date_time [value] => 1307734041 [compare] => >= [type] => NUMERIC ) ) )
Score, I *was* something simple. My args were looking for date_time and my array holds date_value.
$args = array( 'post_type' => 'closings' ,'posts_per_page' => 1000 ,'meta_query' => array( array( 'key' => 'date_value', 'value' => $now, 'compare' => '>=', 'type' => 'NUMERIC' ) ) );
- The topic ‘meta_query of unix timestamp to custom field’ is closed to new replies.