Support

Account

Home Forums General Issues Sorting by Custom Fields, with Priority Reply To: Sorting by Custom Fields, with Priority

  • ractoon, thanks for your help! That code led me in the right direction. I did end up having to use 2 queries.

    First I checked for department heads:

    <?php //Get the Department Head First ?>
    <?php
    $args = array(
    	'numberposts' => -1,
    	'post_type' => 'staff',
    	'meta_key' => 'dir-department-head',
    	'meta_value' => 'yes'
    
    );
    query_posts($args);
    ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
     
    <?php if (in_array("Administration", (array) get_field('dir-department')) AND ('yes' == get_field('dir-department-head'))): ?>

    Formatting fields, etc.

    <?php endif; ?> 
    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>

    Then, a separate query for the rest of the employees, excluding the “yes” answers in the department head field by pulling only those entries who left the field blank:

    <?php // Get Other Deparment Employees ?>
    <?php
    $args = array(
    'post_type' => 'staff',
    'posts_per_page' => -1,
    'meta_key'	=> 'dir-last-name',
    'orderby' => 'meta_value',
    'order' => 'ASC'
    );
    query_posts($args);
    ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if (in_array("Administration", (array) get_field('dir-department')) AND ('' == get_field('dir-department-head'))): ?>

    Formatting fields, etc.

    <?php endif; ?> 
    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>

    Thanks for leading me in the right direction!