<?php
//Just add this code to your functions.php
add_filter('acf/prepare_field/key=field_1234567890', 'acf_prepare_field_select'); // change the field key to your target
function acf_prepare_field_select($field) {
$choices = $field['choices'];
$field['choices'] = array(); // start from empty
$current_group = '';
foreach($choices as $value => $label) {
// if contain hashtag, turn it into optgroup
if(strpos($label, '#') !== false) {
$current_group = str_replace('#', '', $label);
$field['choices'][$current_group] = array();
}
else {
$field['choices'][$current_group][$value] = $label;
}
}
return $field;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.