Support

Account

Home Forums Add-ons Options Page Problem populating select field choices Reply To: Problem populating select field choices

  • What you have looks like it could work. What will help is to see what’s in those values. Could you alter your function and let me know what’s output when you edit the post.

    
    function acf_load_test1_field_choices( $field ) {
        
        // reset choices
        $field['choices'] = array();
            
        // get the textarea value from options page without any formatting
        $choices = get_field('test2', 'option', false);
        
       // see what's in choices
       echo '<pre>',htmlentities($choices),'</pre>';
     
       // explode the value so that each line is a new array piece
        $choices = explode("\n", $choices);
    
       // see what's in choices
       echo '<pre>'; print_r($choices); echo '</pre>';
        
        // loop through array and add to field 'choices'
        if( is_array($choices) ) {
            
            foreach( $choices as $choice ) {
                
                $field['choices'][ $choice ] = $choice;
                
            }
            
        }
        
        // see what's in choices
        echo '<pre>'; print_r($field['choices']);
    
        // return the field
        return $field;    
    }
    add_filter('acf/load_field/name=test1', 'acf_load_test1_field_choices');