acf_get_taxonomy_terms() ACF 5.0.0
This function will return an array of available taxonomy terms
Хуков нет.
Возвращает
(Массив).
Использование
acf_get_taxonomy_terms( $taxonomies );
- $taxonomies **
- -
По умолчанию: array()
Список изменений
С версии 5.0.0 | Введена. |
Код acf_get_taxonomy_terms() acf get taxonomy terms ACF 5.9.1
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;
}