Querying custom post type with 2 custom fields (date-range)

Here is the code I ended up with that works. I should have mentioned that the query was inside the loop, because when I showed it to Damian Taggart of Mindshare Studios, he noticed that he said I should be using WP_Query instead of query_posts. Thanks to Milo and others for attempting to help me without having all the necessary info.

<?php
     $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
     $today = date('Y-m-d', strtotime('-6 hours'));
     $myquery = new WP_Query(array(
     'post_type' => 'exhibitions', 
     'posts_per_page' => 6,  
     'paged' => $paged,
     'orderby' => 'title',
     'order' => 'ASC',
     'meta_query'=>array(
            'relation'=>'AND',
            array(
                'key' => 'exstart-date',
                'value' => $today,
                'compare' => '<=',
                'type' => 'CHAR'
            ),
            array(
                'key' => 'exend-date',
                'value' => $today,
                'compare' => '>=',
                'type' => 'CHAR'
            )
        )
    ));
    if ($myquery->have_posts()) :
    while ($myquery->have_posts()) : $myquery->the_post();
?>

Leave a Comment

tech