Support

Account

Home Forums Front-end Issues Select field based on other fields value Reply To: Select field based on other fields value

  • Finally, I’ve managed to succesfully populate the repeater field in a select field in every users panel with this function

    function acf_load_select_field_field_choices($field) {
        global $current_user;
        //Get the repeater field values
        $choices = get_field('repeater_field_name',$current_user);
    	$field['choices'] = [];
        // loop through array and add to field 'choices'
        if (is_array($choices)) {
            foreach ($choices as $choice) {
                //Set the select values
                $field['choices'][$choice['subfield']] = $choice['subfield'];
            }
        }
        // return the field
        return $field;
    }
    add_filter('acf/load_field/name=select_field', 'acf_load_select_field_field_choices');

    The only problem that I’m facing right now is that the select field doesn’t update when submitting a form.

    The code that I’m using to display and update the select field is the following

    <?php 
       $field = get_field_object('repeater_field_key');
          if (!empty($field['choices'])) { ?>
               <select>
                    <?php foreach ($field['choices'] as $v => $l) { ?>
                        <option value="<?php echo $v; ?>"><?php echo $l; ?></option>
                    <?php } ?>
               </select>
          <?php } 
          $current_user_id = get_current_user_id();
          update_field($field, $field['value'], 'user_'.$current_user_id); 
    ?>

    What am I doing wrong?