Home › Forums › Add-ons › Repeater Field › Radio Buttons and Repeater fields….
Okay guys, have what hopefully should be a simple thing to do but I cannot for the life of me figure this out….
I have a set of repeater fields, one of the repeater fields is a radio button with choices of “left, right, center.”
What I want to do, is have is so that a user chooses the radio button, and on the front end it just applies whatever the value is to a class… like this: <h2 class=”left”> (left would be the choice they user put, and it literally just puts that as the class name. I would then just apply a style for “align left”, etc.
However, I cant get ANY value from the radio button to appear on the page, even though I have other advanced custom fields that appear on the page correctly… here’s what I am trying to do… can someone please help steer me in the right direction? “imagealigned” and “titlealigned” is the name of the custom field. Headline works, which is just text a user puts in…
<?php if( have_rows(‘rowtop’) ): ?>
<?php while( have_rows(‘rowtop’) ): the_row();
echo ‘<div class=”rowtop”>’;
echo ‘<main id=”main” role=”main” class=”container m-t-lg m-b-lg”>’;
// vars
$headline = get_sub_field (‘headline’);
$titlealigned = get_sub_field(‘titlealigned’);
$imagealigned = get_sub_field(‘imagealigned’);
?>
<?php if( $headline ): ?>
<?php
echo ‘<h2 class=”‘. $titlealigned.'”>’;// display a sub field value
the_sub_field(‘headline’);
echo ‘</h2>’;
?>
<?php endif; ?>
<?php if( $image ): ?>
<?php
echo ‘<img class=”‘. $imagealigned.'” src=”‘;// display a sub field value
the_sub_field(‘image’);
echo ‘/>’;
?>
<?php endif; ?>
<?php $image = get_sub_field(‘image’);
//Checking if anything exists for the image field
if ($image) { ?>
<?php echo ‘<img src=”‘;// display a sub field value
the_sub_field(‘image’);
echo ‘/>’;
?>
<?php } //if there is nothing for image then display
else { ?>
<?php }
?>
<?php echo $content; ?>
<?php
echo ‘</main>’;
echo ‘</div>’;
?>
<?php endwhile; ?>
<?php endif; ?>
</div>
What do you get if you echo out the values right after getting them?
// vars
$headline = get_sub_field (‘headline’);
$titlealigned = get_sub_field(‘titlealigned’);
$imagealigned = get_sub_field(‘imagealigned’);
// what values are being returned?
echo $titlealigned,':',$imagealigned;
Thanks for the reply, hmm I still get the same result – nothing on the front end displays at all. Example, it shows <h2 class></h2>
I think the issue is that it just does not display the values of “left” “right” or “center.” Does something else have to happen for those to appear?
A radio field stores a single text value. There are a couple of reasons that it might not return anything; using the wrong field name, no value selected, no values to select, trying to get the field in the wrong context. There might be some other reasons but nothing I can figure out without also seeing the field group. Can you export the field group put it in a .zip file and attach it? Maybe I can figure it out by looking at that.
The topic ‘Radio Buttons and Repeater 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.