Im using ACF repeater to generate results form a list, which is all working fine. But, rather than display the list value, I want to display the list label.
Here is the code:
<ul class="notifications-content">
<?php while(has_sub_field('notification')):
$house = get_sub_field('house');
$year = get_sub_field('year');
$date = DateTime::createFromFormat('Ymd', get_sub_field('date'));
$newDate = date("D j F", strtotime($date->format('d-m-Y')));
?>
<li class="<?php echo safe_url($house); ?> <?php echo $year; ?>">
<h2 class="black"><?php echo str_replace($replace, '', get_sub_field('message')); ?></h2>
<h3 class="interstatebold white uppercase"><?php echo $house; echo $year ? ", $year" : ''; echo ' | '.$newDate; ?></h3>
<?php echo get_sub_field('urgent') ? '<div class="circle"></div>' : ''; ?>
</li>
<?php endwhile; ?>
</ul>
How do I get the label?
Take a look at this official documentation about get_field_object
There is a usage example in the bottom:
You can use this in your repeater to grab that field_object you want and display the label.
Instead of using has sub field, use get_field(‘platforms’). Put respective repeater field name in place of ‘platforms.’ Platforms is the name of repeater field.
By using foreach loop with key=>value pair, you get key as well as value.
Try using following code.
You can use it the same way you would call the field values by passing it through these functions (add to functions.php):
Usage:
<?php echo get_field_label('field-slug'); ?>
Usage:
<?php the_field_label('field-slug'); ?>