Home › Forums › General Issues › Get select field label within repeater
I want to get the value of ‘select’ field within my repeater field. The solutions I’ve found don’t seem to work – I think it’s because I’m within an array. Here’s my code – I want the H2 in this example to start with the label of the ‘area’ select field, instead of the value:
$representativeArray = get_field('sales_representatives');
if (!empty($representativeArray)) {
usort($representativeArray, 'sortByGroup');
$last_group = ''; // initialize the group name
foreach ($representativeArray as $representative) {
$this_group = $representative['area'];
if ($this_group != $last_group) {
if ($last_group != '') { ?>
</div>
</div>
</div><!-- ./remodal -->
<?php }
$last_group = $this_group; ?>
<div class="remodal sales-representatives-remodal" data-remodal-id="modal-<?php echo $representative['area']; ?>">
<button data-remodal-action="close" class="remodal-close"></button>
<h2><?php echo $representative['area']; ?> Sales Team</h2>
<div class="row">
<div class="col-sm-8 text-left">
<?php }
if( $representative['name'] ) {
$representative_name = '<i class="fa fa-user-circle color-'.$representative['area'].'"></i><strong>'.$representative['name'].'</strong><br>';
}
if( $representative['email'] ) {
$representative_email = '<i class="fa fa-envelope"></i><a href="mailto:'.$representative['email'].'">'.$representative['email'].'</a><br>';
}
echo $representative_name;
echo $representative_email;
echo '
';
} // end foreach
} // end if personArray
?>
for reference I have tried this solution, but it’s not working for me:
Any help appreciated!
Hi @elsmore
For nested fields such as your select field, you will need to make use of a repeater loop. This can be achieved by using the have_rows() loop and then call the select field within this by making use of the get_sub_field() function as described on this page: https://www.advancedcustomfields.com/resources/repeater/
I hope this info helps.
The topic ‘Get select field label within repeater’ 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.