Support

Account

Home Forums Backend Issues (wp-admin) Dropdown value saved but not loaded back Reply To: Dropdown value saved but not loaded back

  • Hi @tazintosh

    I’m not sure how you get the $databaseValue variable, but I believe you need to get the database value by using the get_field() function instead. For a single select field, you should be able to do it like this:

    function my_acf_load_database_value($field){
        // get the current post
        global $post;
        
        // get the database value
        $db_value = get_field($field['name'], $post->ID, false);
        
        //set the choices
    	$field['choices'][$db_value] = $db_value;
        
    	return $field;
    }
    add_filter('acf/load_field/key=' . $imageSizeSelect, 'my_acf_load_field', 20, 1);

    But is seems you are using the repeater field to contain the select fields. In this case, you can try the following code:

    function my_acf_load_database_value($field){
        // get the current post
        global $post;
        
        // get the database value
        $db_value = get_field('repeater_field_name', $post->ID, false);
        
        // loop through the repeater value
        foreach( $db_value as $row ){
            
            // get the current row value
            $row_select_value = $row[$field['key']];
            
            // set the choices
            $field['choices'][$row_select_value] = $row_select_value;
        }
        
        // return
    	return $field;
    }
    add_filter('acf/load_field/key=' . $imageSizeSelect, 'my_acf_load_field', 20, 1);

    If that doesn’t work, could you please share the JSON export file of your field group so I can test it out on my installation?

    Thanks 🙂