Title: Multiple Queries in one loop (custom fields)
Last modified: August 20, 2016

---

# Multiple Queries in one loop (custom fields)

 *  [Tailzip](https://wordpress.org/support/users/tailzip/)
 * (@tailzip)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/multiple-queries-in-one-loop/)
 * 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=now
 * To 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.

## Tags

 * [custom-query](https://wordpress.org/support/topic-tag/custom-query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Tailzip](https://wordpress.org/support/users/tailzip/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/multiple-queries-in-one-loop/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
