acf_walk_select_input() ACF 5.6.0
Returns the HTML of a select input's choices.
Хуков нет.
Возвращает
Строку.
Использование
acf_walk_select_input( $choices, $values, $depth );
- $choices(массив)
- The choices to walk through.
- $values(массив)
- The selected choices.
- $depth(массив)
- The current walk depth.
Список изменений
С версии 5.6.0 | Введена. |
Код acf_walk_select_input() acf walk select input ACF 5.9.1
function acf_walk_select_input( $choices = array(), $values = array(), $depth = 0 ) {
$html = '';
// Sanitize values for 'selected' matching (only once).
if( $depth == 0 ) {
$values = array_map('esc_attr', $values);
}
// Loop over choices and append to html.
if( $choices ) {
foreach( $choices as $value => $label ) {
// Multiple (optgroup)
if( is_array($label) ){
$html .= sprintf(
'<optgroup label="%s">%s</optgroup>',
esc_attr($value),
acf_walk_select_input( $label, $values, $depth+1 )
);
// single (option)
} else {
$attrs = array(
'value' => $value
);
// If is selected.
$pos = array_search( esc_attr($value), $values );
if( $pos !== false ) {
$attrs['selected'] = 'selected';
$attrs['data-i'] = $pos;
}
$html .= sprintf( '<option %s>%s</option>', acf_esc_attr($attrs), esc_html($label) );
}
}
}
return $html;
}