get_term_field() WP 1.0
Get sanitized Term field.
The function is for contextual reasons and for simplicity of usage.
Works based on: sanitize_term_field()
Basis of: term_description()
No Hooks.
Return
String/Int/null/WP_Error. Will return an empty string if $term is not an object or if $field is not set in $term.
Usage
get_term_field( $field, $term, $taxonomy, $context );
- $field(string) (required)
- Term field to fetch.
- $term(int/WP_Term) (required)
- Term ID or object.
- $taxonomy(string)
- Taxonomy Name.
Default: '' - $context(string)
- How to sanitize term fields. Look at sanitize_term_field() for available options.
Default: 'display'
Notes
- See: sanitize_term_field()
Changelog
Since 2.3.0 | Introduced. |
Since 4.4.0 | The $taxonomy parameter was made optional. $term can also now accept a WP_Term object. |
Code of get_term_field() get term field WP 5.6
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 );
}Related Functions
From tag: Term (taxonomies terms)
- get_term()
- get_term_by()
- get_term_children()
- get_term_link()
- get_terms()
- get_the_term_list()
- get_the_terms()
More from category: Any taxonomy
- edit_term_link()
- get_edit_term_link()
- get_taxonomies()
- get_taxonomy()
- is_taxonomy_hierarchical()
- register_taxonomy()