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:
<?php
$args = array(
'post_type' => 'staff',
'posts_per_page' => -1,
'meta_key' => 'dir-last-name',
'orderby' => 'meta_value',
'order' => 'ASC'
);
query_posts($args);
?>
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 😉
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.