mercredi 4 février 2015

Filter query based on date in custom field


I have a custom post type jobs and custom field with key expiry-date which the user enters the date after which the post will no longer be displayed.


Here's my code so far...



$loop = new WP_Query( array(
'post_type' => 'jobs',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'date',
'meta_query' => array (
'key' => 'expiry-date',
'value' => date('d/m/Y',strtotime("today")),
'type' => 'DATE',
'compare' => '>='
)
));

if (have_posts()) : while ($loop->have_posts()) : $loop->the_post();
[display content]
endwhile; else:
[display "no vacancies" message]
endif;


The date in expiry-date is stored in the format dd/mm/yyyy (although some posts may have this field empty). I'd like to only return posts in the query where the expiry date is greater than today's date (or doesn't have a date set) - I've tried various values and compare types what am I missing?





Aucun commentaire:

Enregistrer un commentaire