Home › Forums › Add-ons › Repeater Field › Output repeater field with radio button sub fields
I have tried working with the various support code examples to output one of my custom fields at the front end of my website, but I can’t figure out the solution.
I have setup a few custom fields that have a repeater field type and the sub fields are radio buttons. See the image – this is how users of the site fill out the custom field in the WordPress Dashboard. The custom fields are part of a survey.
Q1: How do I loop through and output all the ‘labels’ of each sub field within a repeater field, and the ‘choice’ of each radio sub field in the front end of my website.
Q2: How can I output the repeater rows based on the user’s choice – ascending or descending? The radio buttons act as a ranking scale from 1 to 5.
Any advice on how to achieve these two options is much appreciated.
Q1: In order to get the labels you’d have to also fetch the field object.
this can be done with get_field_object()
. It will be an array containing the field label as well as the choices with key => value pairs (and more).
Q2: I believe what you want is to sort the repeater field based on the radio fields. Have a look at this: http://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/
That might be enough to get you going!
Hi Jonathon, Thank you for your assistance.
To clarify:
Part 1
I have put the functions part of the code (from here: sort a repeater field) in my functions.php file. I have replaced the field key with my relevant custom field key.
The part of this function that I don’t understand is this part:
add_filter('acf/load_value/name=scores', 'my_acf_load_value', 10, 3);
What do I need to change here, and to what?
And, do I repeat this function when I have more than one custom field to sort?
Part 2
Then I have put the php code within my single_custom_post_type.php file and replaced ‘repeater’ with my same field key as used in the function.
<?php if( have_rows('field_5650dfe9c5250') ): ?>
<ul>
<?php while( have_rows('field_5650dfe9c5250') ): the_row(); ?>
<li><?php the_sub_field('id'); ?>. <?php the_sub_field('name'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
I am not getting any result?
Where am I going wrong?
The topic ‘Output repeater field with radio button sub fields’ 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.