Support

Account

Home Forums Backend Issues (wp-admin) acf/load_field not displaying selected items in dropdown after save.

Unread

acf/load_field not displaying selected items in dropdown after save.

  • I am using the following code…

    function pwdctest_choices( $field ) {
    
        // reset choices
        $field['choices'] = array();
    
        $terms = get_terms( array(
            'taxonomy' => 'practice_areas',
            'hide_empty' => false,
        ) );
    
        $i = 0;
        foreach ($terms as $term){
            $choices[$i]['name'] = $term->name;
            $choices[$i]['slug'] = $term->slug;
            $choices[$i]['id'] = $term->term_id;
            $i++;
        }
    
        // loop through array and add to field 'choices'
        if( is_array($choices) ) {
    
            foreach( $choices as $choice ) {
    
                $field['choices'][$choice['name']] = $choice['name'];
    
            }
    
        }
    
        // return the field
        return $field;
    
    }
    
    add_filter('acf/load_field/name=pwdctest_choices_field', 'pwdctest_choices');

    this is what is being returned from the above function…

    `array(1) {
    [“choices”]=>
    array(14) {
    [“Branded Environments”]=>
    string(20) “Branded Environments”
    [“Civic and Cultural”]=>
    string(18) “Civic and Cultural”
    [“Corporate and Commercial”]=>
    string(24) “Corporate and Commercial”
    [“Corporate Interiors”]=>
    string(19) “Corporate Interiors”
    [“Healthcare”]=>
    string(10) “Healthcare”
    [“Higher Education”]=>
    string(16) “Higher Education”
    [“Hospitality”]=>
    string(11) “Hospitality”
    [“K-12 Education”]=>
    string(14) “K-12 Education”
    [“Landscape Architecture”]=>
    string(22) “Landscape Architecture”
    [“Planning and Strategies”]=>
    string(23) “Planning and Strategies”
    [“Science and Technology”]=>
    string(22) “Science and Technology”
    [“Sports, Recreation and Entertainment”]=>
    string(36) “Sports, Recreation and Entertainment”
    [“Transportation”]=>
    string(14) “Transportation”
    [“Urban Design”]=>
    string(12) “Urban Design”
    }
    }’

    when I save the post it does save to the database but the multi select shows nothing.

    Not sure but it seems that this should work. Any help would be appreciated.

    Thanks!!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.