Multiple Queries in one loop (custom fields)
-
Hello,
I have, on my category.php page, some filters to sort out results.
In this example, I want to sort “Expositions” by these terms : ‘date’, ‘zip_code’,’subcategory’.I made links like this :
<a href="<?php echo add_query_arg(array('date' => 'now')); ?>">Now</a>, so I have this URL : …/expositions/?date=nowTo sort out by ‘date’, I use this arguments for my custom query :
$date_args = array('meta_query' => array( 'relation'=>'AND', array( 'key' => 'date_start', 'value' => date('Y m d'), 'compare' => '<=', 'type' => 'CHAR'), array( 'key' => 'date_end', 'value' => date('Y m d'), 'compare' => '>=', 'type' => 'CHAR' )));Then I merge my args :
$args = array_merge( $wp_query->query, $date_args ); query_posts($args);This works fine, but I’m trying to “mix” terms to sort results, I get into trouble…
To sort out by ‘zone’, I use this arguments for my custom query :
$zone_args = array('meta_query' => array( array( 'key' => 'code_postal', 'value' => $listeZones['paris_c'], 'compare' => 'IN', 'type' => 'numeric' )) );I’m looking for a solution to mix both custom queries. Because if my URL parameters are “?date=now&zone=paris_center”, I want ONLY posts that match both criterias.
I don’t know if I’m clear…sorry for my bad english.
Thanks for help ! 🙂
The topic ‘Multiple Queries in one loop (custom fields)’ is closed to new replies.