Gets sanitized term field.
The function is for contextual reasons and for simplicity of usage.
$fieldstringrequired
$termint|WP_Termrequired
$taxonomystringoptional
Default:''
$contextstringoptional
'display'.'raw', 'edit', 'db', 'display', 'rss', 'attribute', or 'js'. Default 'display'.Default:'display'
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 );
}
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_term_field