We’ve done a WordPress searchform and we don’t manage to make a PHP string working well outside a for statement.
We’re using a WordPress Query to make the filter work. As you’ll see, we’ve been using different custom fields.
The rest of strings such as $height and $tshirt_size- are defined hundreds of lines below and work perfectly.
The only problem we’ve got is that we cannot make the $all_dates string work outside the for statement.
When we try to print it inside works fine and shows all the dates we are requesting. But when we try to do it outside, only shows one date (the last one).
That is how the query works (I hope the annotations are clear enough):
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( array(
'post_type' => 'bbdd',
'paged' => $paged,
'meta_query' => array(
$tshirt_size, /*WORKS WELL*/
$shoe_size, /*WORKS WELL*/
$height, /*WORKS WELL*/
$weight, /*WORKS WELL*/
array( 'key' => 'age',
'value' => array($all_dates) /*NOT WORKING*/ ),)) );
$date_from = $_GET["date_from"];
$date_from = strtotime($date_from);
$date_to = $_GET["date_to"];
$date_to = strtotime($date_to);
for ($i=$date_from; $i<=$date_to; $i+=86400)
{
$all_dates = "'" . date("d/m/Y", $i) . "', ";
echo $all_dates; /*PRINTING ALL DATES*/
}
echo $all_dates; /*PRINTING ONLY ONE DATE (LAST DATE)*/ ?>
try this