acf_field_taxonomy::get_terms
get_terms
This function will return an array of terms for a given field value
Method of the class: acf_field_taxonomy{}
No Hooks.
Returns
$value.
Usage
$acf_field_taxonomy = new acf_field_taxonomy(); $acf_field_taxonomy->get_terms( $value, $taxonomy );
- $value(required)
- .
- $taxonomy
- .
Default:'category'
Changelog
| Since 5.0.0 | Introduced. |
acf_field_taxonomy::get_terms() acf field taxonomy::get terms code ACF 6.0.4
function get_terms( $value, $taxonomy = 'category' ) {
// load terms in 1 query to save multiple DB calls from following code
if ( count( $value ) > 1 ) {
$terms = acf_get_terms(
array(
'taxonomy' => $taxonomy,
'include' => $value,
'hide_empty' => false,
)
);
}
// update value to include $post
foreach ( array_keys( $value ) as $i ) {
$value[ $i ] = get_term( $value[ $i ], $taxonomy );
}
// filter out null values
$value = array_filter( $value );
// return
return $value;
}