Querying custom post type with 2 custom fields (date-range)
Ho cercato nel WP Codex e su StackExchange e ho ottenuto alcuni indizi, ma non riesco a far funzionare questa query. Ho 2 campi personalizzati associati a ogni mostra nel formato Y-m-d: exstart-date rappresenta la data di inizio della mostra e exend-date la data di fine.
Riesco facilmente a visualizzare le mostre future e quelle passate, ma non riesco a impostare correttamente la meta_query per mostrare le mostre correnti (con una data di inizio minore o uguale a oggi E una data di fine maggiore o uguale a oggi). Il codice seguente non mostra nulla nella pagina. Aiuto?
$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();

Ecco il codice con cui ho finito per ottenere il risultato desiderato. Avrei dovuto specificare che la query era all'interno del loop, perché quando l'ho mostrato a Damian Taggart di Mindshare Studios, ha notato che avrei dovuto usare WP_Query invece di query_posts. Ringrazio Milo e gli altri per aver tentato di aiutarmi nonostante non avessero tutte le informazioni necessarie.
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$today = date('Y-m-d', strtotime('-6 ore'));
$myquery = new WP_Query(array(
'post_type' => 'mostre',
'posts_per_page' => 6,
'paged' => $paged,
'orderby' => 'title',
'order' => 'ASC',
'meta_query'=>array(
'relation'=>'AND',
array(
'key' => 'data-inizio',
'value' => $today,
'compare' => '<=',
'type' => 'CHAR'
),
array(
'key' => 'data-fine',
'value' => $today,
'compare' => '>=',
'type' => 'CHAR'
)
)
));
if ($myquery->have_posts()) :
while ($myquery->have_posts()) : $myquery->the_post();
?>
