Home › Forums › Add-ons › Repeater Field › Show repeater rows based on radio value
I have a radio field in my repeater group with the values ‘Row One’ and ‘Row Two’. I would like to show all repeater rows with the value ‘Row One’ in one spot and all the repeater shows with the radio value ‘Row Two’ in a different spot. Is this possible? I’ve tried doing if (in_array) and also tried testing for the value stored in a variable but failed at both attempts.
Hi @amycarolyn
All that is needed is some simple PHP logic like so:
<?php if(get_field('repeater_field_name')): ?>
<ul>
<?php while(has_sub_field('repeater_field_name')): ?>
<?php if( get_sub_field('select') == 'Row One' ): ?>
<?php // do this... ?>
<?php else: ?>
<?php // do that... ?>
<?php endif; ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Good luck!
Hi Elliot,
I’m trying to do something similar. I tried the code above and it didn’t work for me.
I’m trying to create a page with Events Listings. But I’d just like to use one repeater field that has about 6 sub-fields. One of those sub-fields is a selection field called “date_category” with a selection of Current Event and nothing else. So the user would then select if the event is current or if they select nothing, it will go into the archived section of the page. In my template, I’ve duplicated the repeater fields in both selections… see my code…I would actually like to place all the Archived Listings inside a Jquery accordion, so that all the archives would be hidden until the user expands them, but the current events would be listed one after the other, as normal. The problem is that my code creates an accordion for each listing, instead of grouping them all together under one accordion. See my code below. Is there a way to group them?
Thanks for your help.
<div class="events">
<?php if(get_field('event_listings')): ?>
<?php while(has_sub_field('event_listings')): ?>
<?php if(get_sub_field('date_category') == "Current Event") { ?>
<div class="event_listings">
<div class="date"><strong>Event Date:</strong> <?php the_sub_field('date'); ?></div>
<div class="title"><?php the_sub_field('title'); ?></div>
<p><?php the_sub_field('description'); ?></p>
<div class="meta"><strong>Time:</strong> <?php the_sub_field('time'); ?></div>
<div class="meta"><strong>Location:</strong> <?php the_sub_field('location'); ?></div>
<div class="meta"><strong>Attendance:</strong> <?php the_sub_field('attendance'); ?></div>
<div class="meta"><strong>Type:</strong> <?php the_sub_field('type'); ?></div>
</div><!--End Event Listings-->
<?php } else { ?>
<div class="expand">Archived Listings</div>
<div class="event_listings collapse">
<div class="date"><strong>Event Date:</strong> <?php the_sub_field('date'); ?></div>
<div class="title"><?php the_sub_field('title'); ?></div>
<p><?php the_sub_field('description'); ?></p>
<div class="meta"><strong>Time:</strong> <?php the_sub_field('time'); ?></div>
<div class="meta"><strong>Location:</strong> <?php the_sub_field('location'); ?></div>
<div class="meta"><strong>Attendance:</strong> <?php the_sub_field('attendance'); ?></div>
<div class="meta"><strong>Type:</strong> <?php the_sub_field('type'); ?></div>
</div><!--End Event Listings-->
<?php } ?>
<div style="margin-bottom:20px;"></div>
<?php endwhile; ?>
<?php else : ?>
<p>There are no event listings at this time.</p>
<?php endif; ?>
</div>
Hi @marindee
This sounds like a general ‘how to’ WP theme dev question and is not really related to an issue or bug with ACF.
I am unable to help out with these kinds of questions due to my workload. If you have any issues with specific bugs / functions, let me know.
Thanks
E
The topic ‘Show repeater rows based on radio value’ 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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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.