Support

Account

Home Forums General Issues Setting up conditional statement using a checkbox value within a repeater field

Helping

Setting up conditional statement using a checkbox value within a repeater field

  • I creater a field that’s a repeater, the fields within the repeater are:

    experience_start_year
    experience_end_year
    experience_present

    I am trying to get the value from experience_present, which is “Present”. I’m then trying to write a conditional statement to say that if “Present” is selected, then output x, if not, output y.

    $start_year = get_sub_field('experience_start_year');
     $end_year = get_sub_field('experience_end_year');
     $present = get_sub_field_object('experience_present');
    
    if( $start_year ) :
       $html_out .= '<div class="duration-block">';
       if( $present && in_array('present', $present) ) :
          $html_out .= '<h5>' . $start_year . ' - ' . $present['present'] . '</h5>';
       else :
          $html_out .= '<h5>' . $start_year . ' - ' . $end_year . '</h5>';
       endif;
          $html_out .= '</div>';
    endif;

    This currently doesn’t output neither “Present” or $end_year.

  • What kind of field is experience_present? A checkbox or a true/false field? Please provide more information on this field.

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

The topic ‘Setting up conditional statement using a checkbox value within a repeater field’ is closed to new replies.