Home Forums Add-ons Repeater Field Conditional Statements Using Repeater


Conditional Statements Using Repeater

  • Hi all!
    Thank you in advance for any help. Here is what I am trying to do but cant seem to figure out. I have the repeater add-on activated and have 3 fields that work fine…
    1. company_name
    2. company_url
    3. company_phone

    The issue I am running into is that I would like to make the repeater fields listed above all conditional so that if I don’t have the company_url field completed all that will display on the page are the other two fields. I am trying to avoid having the URL heading with no url link display on the page… I hope this makes sense.

  • Hi @agraves912

    This can be accomplished with some simple PHP to first check the value before rendering it onto the page.

    Perhaps you should first research how conditional checks work in PHP, then read over the ACF code examples page.


  • I am trying to do the same thing, don’t suppose you can share the PHP to help achieve this. ACF does powerful things for those that don’t know PHP.

    It would also be nice to have this feature available with ACF in future.


  • Hi @iamjustoneman

    You can find examples of an if statement on the code examples page


  • I struggled to get it working within the repeatable field, are there any specific examples of the if statement within the the repeatable field with sub fields?

    <?php if(get_field('repeater_field_name')): ?>
    	<?php while(has_sub_field('repeater_field_name')): ?>
    		<?php if( get_sub_field('sub_field_1') ): ?>
    			<li>sub_field_1 = <?php the_sub_field('sub_field_1'); ?></li>
    		<?php endif; ?>
    	<?php endwhile; ?>
    <?php endif; ?>
  • Brilliant, I will give that a try later on today.


Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Conditional Statements Using Repeater’ is closed to new replies.