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!
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.