Support

Account

Home Forums General Issues Dynamic Select from Options Textarea – Not saving selected value on post edit Reply To: Dynamic Select from Options Textarea – Not saving selected value on post edit

  • Hi elliot,

    Here is the code for the option:

    if( function_exists('acf_add_options_sub_page') ) {
        acf_add_options_sub_page(array(
            'title' => 'Settings',
            'parent' => 'edit.php?post_type=bne_team_schedule',
            'capability' => 'edit_posts'
        ));
    }
    
    function bne_team_schedule_team_names_load_field( $field ) {
    	$field['choices'] = array();
     
    	$choices = get_field('bne_team_schedule_team_names_options', 'option');
     
    	$choices = explode("\n", $choices);
     
    	if( is_array($choices) ) {
    		foreach( $choices as $choice ) {
    			$field['choices'][$choice] = $choice;
    		}
    	}
     
        // Important: return the field
        return $field;
    }
    add_filter('acf/load_field/name=bne_team_schedule_home_team_name', 'bne_team_schedule_team_names_load_field');
    

    Attached is screenshot of the option field which is subpage of the CPT and a screen of what is outputted into the select field within ACF. Like I said, the database seems to store the correct choice but when you update the post the select field, visually, resets to the first choice in the list.

    Using ACF v4.3.0 and Options v1.2.0