I've searched WP Codex and StackExchange and gotten some clues, but I can't get this query working. I have 2 custom fields associated with each exhibition in Y-m-d format: exstart-date being the start date of the exhibition and exend-date being the ending date.
I can easily display upcoming exhibits and past exhibits, but I cannot get the meta_query right to display current exhibits (with a start date less than or equal to today AND end date greater than or equal to today). The code below displays nothing on the page. Help?
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$today = date('Y-m-d', strtotime('-6 hours'));
query_posts(array(
'post_type' => 'exhibitions',
'posts_per_page' => 6,
'paged' => $paged,
'orderby' => 'title',
'order' => 'DESC',
'meta_query'=>array(
'relation'=>'AND',
array(
'key' => 'exstart-date',
'value' => $today,
'compare' => '<=',
'type' => 'CHAR'
),
array(
'key' => 'exend-date',
'value' => $today,
'compare' => '>=',
'type' => 'CHAR'
)
)
));
if (have_posts()) :
while (have_posts()) : the_post();
'type' => 'CHAR', should be'type' => 'DATE', no? – Milo Sep 11 '11 at 23:20caller_get_postsis a true/false parameter, but has been replaced withignore_sticky_posts, though that shouldn't really affect the query, you just get a deprecated notice. I tried it here and it seems to be working, maybe verify that nothing else is interfering with the query, like a plugin,print_r($wp_query)and inspect the contents. – Milo Sep 12 '11 at 2:45$wp_query. it works as-is for me when I just copy/paste your code and add the proper meta fields (i'm also changing the post_type to one I already have set up). are your meta field dates formattedyyyy-mm-dd? I don't imagine the other queries you're doing would work if they weren't. – Milo Sep 12 '11 at 15:18