• 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)
  • 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.