Support

Account

Home Forums General Issues How do I get optgroups in the Select field? Reply To: How do I get optgroups in the Select field?

  • As an update, this appears to be in the default ACF with a action hook now. For example:

    
    add_filter('acf/load_field/key=field_12345678', 'acf_create_select');
    function acf_create_select( $field ) {
    	$field['choices'] = array();
    	$choices = get_my_options();
    	foreach( $choices as $t ) {
    		if ( !isset( $field['choices'][ $t->optgroup ] ) )
    			$field['choices'][ $t->optgroup ] = array();
    		$field['choices'][ $t->optgroup ][ $t->item_value ] = $t->item_text;
    	}
    	return $field;
    }