I’m working with WordPress and WP-Types plugin and need to sort CPT by a custom field date.
This work fine:
$args = array(
'post_type' => 'parties',
'paged' => $paged,
'meta_key' => 'wpcf-parties_date',
'orderby' => 'meta_value',
'order' => 'DESC',
);
The orderby works perfect.
On the Database the value of the field date ‘wpcf-parties_date’ is store in this way ex: 1349481600 .
I have two templates where i need to show past and upcoming Posts. My question is how can i display only the future or past posts regarding the current date?
I try this with no luck.
$args = array(
'post_type' => 'parties',
'paged' => $paged,
'meta_key' => 'wpcf-parties_date',
'meta_value' => date('d.m.Y H:i:s'),
'meta_compare' => '>',
'orderby' => 'meta_value',
'order' => 'ASC'
);
I using WP_Query for the loop.
Thanks in advance!!
You may try
meta_query
to check both< and >
and also usemeta_value_num
because your custom field value is numeric (1349481600).Read the documentation for more.