Home › Forums › Add-ons › Repeater Field › Hide the title if the repeater's subfields are empty › Reply To: Hide the title if the repeater's subfields are empty
If title is a sub field this should work. If it’s not a sub field, change it to get_field(‘title’)
<?php if( have_rows('repeater_field_name') ): $title = get_sub_field('title'); $repeater_subfield_name = get_sub_field('repeater_subfield_name'); if( !empty($repeater_subfield_name) ): ?> <h2><?php echo $title ?></h2> // need to hide this if subfield is empty <?php endif; ?> <ul> <?php while ( have_rows('repeater_field_name') ) : the_row(); ?> <li><?php echo $repeater_subfield_name ?></li> <?php endwhile; ?> </ul> <?php endif; ?>
Hope it works. 🙂
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.