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

  • Thanks! I have thought about doing 2 queries but I’m trying to salvage the setup of the their template if possible.

    Right now I’ve got a query like this:

    $args = array(
    'post_type' => 'staff',
    'posts_per_page' => -1,
    'meta_key'	=> 'dir-last-name',
    'orderby' => 'meta_value',
    'order' => 'ASC'

    So that is grabbing everyone’s last name and sorting it. The template also has this bit of code, which I’m hoping to modify:

    <?php if (in_array("Administration", (array) get_field('dir-department'))): ?>

    In this bit, it’s looking for entries in the Administration department. Code below that (not included here) formats the entry nicely.

    What I would love to do is modify this to also look for a value of “yes” in the ‘dir-department-head’ field. So I want to look for someone in the Administration department (like the code above) and then also check to see if they are a Department Head. Basically an if/else statement that checks for a Department Head, then moves on to the rest of the list.

    I know only enough PHP to be dangerous so everything I’ve tried to do doesn’t seem to work 😉