Support

Account

Home Forums Backend Issues (wp-admin) Display selected value from populated select list

Helping

Display selected value from populated select list

  • Hello,

    I’m using a selct list that I populate myself this way :

    function acf_file_field( $field ) {
        $files = array('key1' => 'value1', 'key2' => 'value2');
    
        $field['choices'] = array();
        foreach($files as $file_key => $file_value) {
            $field['choices'][$file_key] = $file_value;
        }
        return $field;
    }
    add_filter('acf/load_field/name=file', 'acf_file_field');

    It displays fine, the value is correctly saved but the current value is not selected when I go back to my form.

    Is there a way to force the selected attribute for the current value ?

  • Try setting the priority

    
    add_filter('acf/load_field/name=file', 'acf_file_field', 20);
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.