Selecting posts older than the current Unix epoch timestamp
I am trying to perform the following query, which originates by the fact the post's 'date' and 'time' are entered as separate custom fields.
$args = array(
'post_type' = 'some_kind_of_posts',
'posts_per_page' = 3,
'orderby' = 'meta_value_num',
'meta_key' = strtotime('date'. ' ' .'time'),
'order' = 'DESC',
'meta_query' = array(
array(
'key' = strtotime('date'. ' ' .'time'),
'value' = strtotime(date('H:i',time() + 3600*2))
'compare' = '',
),
),
);
$query = new WP_Query( $args );
In other words, I need to first combine 'date' and 'time', in order to select posts which are older than the current time. The latter is converted into Unix epoch timestamp (is this a good option ?).
I have elsewhere checked strtotime(get_field('date'). ' ' .get_field('time'))
and strtotime(date('H:i',time() + 3600*2))
by echoing them, and obtained the expected Unix epoch time in seconds.
However, key-value comparison fails: I do not manage to select posts which are older than current time.
Many thanks for any hint on how to tackle the problem.
Topic meta-query timestamp wp-query custom-field custom-post-types Wordpress
Category Web