acf_get_choices_from_grouped_terms()ACF 5.7.5

acf_get_choices_from_grouped_terms

Returns an array of choices from the grouped terms provided.

No Hooks.

Returns

Array.

Usage

acf_get_choices_from_grouped_terms( $value, $format );
$value(array) (required)
A grouped array of WP_Terms objects.
$format(string)
The value format (term_id, slug).
Default: 'term_id'

Changelog

Since 5.7.5 Introduced.

acf_get_choices_from_grouped_terms() code ACF 6.8.8

function acf_get_choices_from_grouped_terms( $value, $format = 'term_id' ) {

	// vars
	$groups = array();

	// loop over values
	foreach ( $value as $group => $terms ) {
		$groups[ $group ] = array();
		foreach ( $terms as $term_id => $term ) {
			$choice                            = acf_get_choice_from_term( $term, $format );
			$groups[ $group ][ $choice['id'] ] = $choice['text'];
		}
	}

	// return
	return $groups;
}