Gets sanitized term field.
Description
The function is for contextual reasons and for simplicity of usage.
See also
Parameters
$field
stringrequired- Term field to fetch.
$term
int|WP_Termrequired- Term ID or object.
$taxonomy
stringoptional- Taxonomy name.
Default:
''
$context
stringoptional- How to sanitize term fields. Look at sanitize_term_field() for available options.
Default'display'
.More Arguments from sanitize_term_field( … $context )
Context in which to sanitize the term field.
Accepts'raw'
,'edit'
,'db'
,'display'
,'rss'
,'attribute'
, or'js'
. Default'display'
.Default:
'display'
Source
function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
$term = get_term( $term, $taxonomy );
if ( is_wp_error( $term ) ) {
return $term;
}
if ( ! is_object( $term ) ) {
return '';
}
if ( ! isset( $term->$field ) ) {
return '';
}
return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.