Title: Filtering by multiple meta values
Last modified: August 19, 2016

---

# Filtering by multiple meta values

 *  [rcburrell](https://wordpress.org/support/users/rcburrell/)
 * (@rcburrell)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/filtering-by-multiple-meta-values/)
 * I’m working on a directory-type page where a list of names and their related 
   info is being displayed; each person is a post inside the “Staff” category. The
   info (job title, phone, email, etc) is being stored via custom fields. Another
   custom field is also provided to allow for control over the order in which the
   names are displayed, much like the post or page order that WP has by default.
   Each name is assigned to a category (Staff, Administration, etc) via another 
   custom field.
 * I want to:
    1) Output a section for each category (Staff, Administration, etc)
   containing only those names and info belonging to that category. 2) AND have 
   them ordered ascending by custom field provided for setting the order number.
 * The issue is that you can’t make a custom query using query_posts() that will
   query based on more than one meta key/value (at least, last I knew). I currently
   have:
 *     ```
       <?php query_posts('category_name=faculty-staff&showposts=80&orderby=meta_value&meta_key=staffOrder&order=ASC'); ?>
       <?php while (have_posts()) : the_post(); ?>
       // I define the variables used below up here
       <div class="staffInfo ">
         <h3><?php the_title(); ?></h3>
         <?php if($staffTitle) { ?>
           <h4><?php echo $staffTitle; ?></h4>
         <?php } ?>
         <?php if($staffEmail or $staffPhone) { ?>
           <dl class="clearfix">
       	<?php if($staffEmail) { ?>
       	  <dt class="staffEmail">Email:</dt>
       	  <dd><?php echo $staffEmail; ?></dd>
       	<?php } ?>
       	<?php if($staffPhone) { ?>
       	  <dt class="staffPhone">Phone:</dt>
       	  <dd><?php echo $staffPhone; ?></dd>
       	<?php } ?>
           </dl>
         <?php } ?>
       </div>
       ```
   
 * Any ideas on where to go from here to sort into the category types before finally
   outputting the sections on the page?

Viewing 1 replies (of 1 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/filtering-by-multiple-meta-values/#post-1207115)
 * So you want to sort posts, first by the custom field you designated as “category”,
   and then within each “category” sort the posts by another custom field (staff
   order)?

Viewing 1 replies (of 1 total)

The topic ‘Filtering by multiple meta values’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [multiple loops](https://wordpress.org/support/topic-tag/multiple-loops/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [sorting](https://wordpress.org/support/topic-tag/sorting/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [16 years, 8 months ago](https://wordpress.org/support/topic/filtering-by-multiple-meta-values/#post-1207115)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
