Home › Forums › General Issues › How to pull in a record if multiple selections were made
I have a staff directory I am working on for a school. I am using a select box that allows multiple selections to select the job type for each staff member. The options are Administration, Elementary and High School. A couple of the teachers also hold an administrative position such as High School Vice Principal and High School Science teacher. They would like to display this persons information and picture in 2 spots in the directory. Once under the Highschool staff section and once under the administration section.
I am trying to figure out how to write my query so that it only shows the administration section only shows:
Here is the code I have so far but it is pulling in all people with a selection of “administration” and “high-school”:
<?php
// args
$args = array(
'numberposts' => -1,
'posts_per_page' => -1,
'post_type' => 'staffinfo',
'meta_query' => array(
'relation' => 'AND',
array(
'meta_key' => 'class_level',
'meta_value' => 'administration',
'compare' => '='
),
array(
'meta_key' => 'class_level',
'meta_value' => 'high',
'compare' => '='
)
)
);
// get results
$the_query = new WP_Query( $args );
$i = 1;
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="staff-member">
<img src="<?php echo get_field('staff_photo'); ?>" alt="<?php echo get_field('staff_member_name'); ?>" />
<div class="staff-info">
<span class="teacher-name"><?php echo get_field('staff_member_name'); ?></span><br />
<span class="duties"><?php echo get_field('classes_taught'); ?></span><br />
<?php if (get_field('email_address')) {?>
<a href="mailto:<?php echo get_field('email_address'); ?>"><?php echo get_field('email_address'); ?></a><br />
<?php } ?>
<?php echo $phone ?>
<?php if ( get_field('phone_extension')) {?>
- Ext. #<?php echo get_field('phone_extension'); ?>
<?php } ?>
</div><!--end staff-info -->
</div><!-- end staff-member -->
<?php if ($i % 5 == 0) { echo "<div class='clearboth'></div>"; } $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Sorry the code didn’t show up correctly.
<?php
// args
$args = array(
'numberposts' => -1,
'posts_per_page' => -1,
'post_type' => 'staffinfo',
'meta_query' => array(
'relation' => 'AND',
array(
'meta_key' => 'class_level',
'meta_value' => 'administration',
'compare' => '='
),
array(
'meta_key' => 'class_level',
'meta_value' => 'high',
'compare' => '='
)
)
);
// get results
$the_query = new WP_Query( $args );
$i = 1;
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="staff-member">
<img src="<?php echo get_field('staff_photo'); ?>" alt="<?php echo get_field('staff_member_name'); ?>" />
<div class="staff-info">
<span class="teacher-name"><?php echo get_field('staff_member_name'); ?></span><br />
<span class="duties"><?php echo get_field('classes_taught'); ?></span><br />
<?php if (get_field('email_address')) {?>
<a href="mailto:<?php echo get_field('email_address'); ?>"><?php echo get_field('email_address'); ?></a><br />
<?php } ?>
<?php echo $phone ?>
<?php if ( get_field('phone_extension')) {?>
- Ext. #<?php echo get_field('phone_extension'); ?>
<?php } ?>
</div><!--end staff-info -->
</div><!-- end staff-member -->
<?php if ($i % 5 == 0) { echo "<div class='clearboth'></div>"; } $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
The topic ‘How to pull in a record if multiple selections were made’ is closed to new replies.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.