Support

Account

Home Forums Add-ons Repeater Field Get value from Checkbox Within Repeater

Helping

Get value from Checkbox Within Repeater

  • Hi all –

    I can’t figure out how in the world to get the value of a checkbox entered in a repeater field. There is only one choice. Basically if the user ticks the checkbox it should output a class.

    In the code example I don’t have the value in the class yet because I am just trying to get it to print something! arg.

    Thanks for your help!

    <?php if( have_rows( 'milestone_module' ) ) : ?>
    
    <section id="tao-timeline">
    
    	<?php 
    
    		while( have_rows( 'milestone_module' ) ) : the_row(); 
    		// Vars
    		$milestone_module_date = get_sub_field( 'milestone_module_date' );
    		$milestone_module_copy = get_sub_field( 'milestone_module_copy' );
    		$field = get_field_object('milestone_long_date');
    		$value = get_field('milestone_long_date');
    		$label = $field['choices'][ $value ];
    	?>
    
    	<div class="tao-timeline-block">
    		<?php if( $milestone_module_date ) : ?>
    			<span class="tao-timeline-date">
    				<?php echo $label; ?>
    				<?php echo $milestone_module_date; ?>
    			</span><!--/.tao-timeline-date-->
    		<?php endif; ?>
    
    		<?php if( $milestone_module_copy ) : ?>
    			<div class="tao-timeline-content">
    				<?php echo $milestone_module_copy; ?>
    			</div><!--/.tao-timeline-content-->
    		<?php endif; ?>
    
    	</div><!--/.tao-timeline-block-->
    
    	<?php endwhile; wp_reset_postdata(); ?>
    
    </section><!--/#tao-timeline-->
    
    <?php endif; ?>
  • Assuming your value is coming from a checkbox in ACF called ‘choices’, you can just get the value using get_field/get_sub_field.

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

The topic ‘Get value from Checkbox Within Repeater’ is closed to new replies.