acf_get_term()
acf_get_term
Similar to get_term() but with some extra functionality.
No Hooks.
Returns
WP_Term.
Usage
acf_get_term( $term_id, $taxonomy );
- $term_id(mixed) (required)
- The term ID or a string of "taxonomy:slug".
- $taxonomy(string)
- The taxonomyname.
Default:''
Changelog
| Since 5.7.3 | Introduced. |
acf_get_term() acf get term code ACF 6.8.8
function acf_get_term( $term_id, $taxonomy = '' ) {
// allow $term_id parameter to be a string of "taxonomy:slug" or "taxonomy:id"
if ( is_string( $term_id ) && strpos( $term_id, ':' ) ) {
list( $taxonomy, $term_id ) = explode( ':', $term_id );
$term = get_term_by( 'slug', $term_id, $taxonomy );
if ( $term ) {
return $term;
}
}
// return
return get_term( $term_id, $taxonomy );
}