Support

Account

Home Forums Front-end Issues How to add item in the post editor?

Helping

How to add item in the post editor?

  • Can I add items in the “selection” type field? As when specifying “category”.
    Either I choose from the list, or I type the content of the field, which is added to the selectable list.
    I tried the “Dynamically populate a select field’s choices” article, but it doesn’t seem to do anything:

    
    function acf_load_editor_field_choices( $field ) {
        
        // reset choices
        $field['choices'] = array();
        // get the textarea value from options page without any formatting
        $choices = get_field('editor', 'option', false);
        // explode the value so that each line is a new array piece
        $choices = explode("\n", $choices);
        // remove any unwanted white space
        $choices = array_map('trim', $choices);
        // loop through array and add to field 'choices'
        if( is_array($choices) ) {
            foreach( $choices as $choice ) {
                $field['choices'][ $choice ] = $choice;
            }
        }
        // return the field
        return $field;
    }
    

    Or does this code not do that?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.