acf_get_taxonomy_terms()ACF 5.0.0

acf_get_taxonomy_terms

This function will return an array of available taxonomy terms

No Hooks.

Returns

(Array).

Usage

acf_get_taxonomy_terms( $taxonomies );
$taxonomies
.
Default: array()

Changelog

Since 5.0.0 Introduced.

acf_get_taxonomy_terms() code ACF 6.8.8

function acf_get_taxonomy_terms( $taxonomies = array() ) {

	// force array
	$taxonomies = acf_get_array( $taxonomies );

	// get pretty taxonomy names
	$taxonomies = acf_get_pretty_taxonomies( $taxonomies );

	// vars
	$r = array();

	// populate $r
	foreach ( array_keys( $taxonomies ) as $taxonomy ) {

		// vars
		$label           = $taxonomies[ $taxonomy ];
		$is_hierarchical = is_taxonomy_hierarchical( $taxonomy );
		$terms           = acf_get_terms(
			array(
				'taxonomy'   => $taxonomy,
				'hide_empty' => false,
			)
		);

		// bail early i no terms
		if ( empty( $terms ) ) {
			continue;
		}

		// sort into hierachial order!
		if ( $is_hierarchical ) {
			$terms = _get_term_children( 0, $terms, $taxonomy );
		}

		// add placeholder
		$r[ $label ] = array();

		// add choices
		foreach ( $terms as $term ) {
			$k                 = "{$taxonomy}:{$term->slug}";
			$r[ $label ][ $k ] = acf_get_term_title( $term );
		}
	}

	// return
	return $r;
}