On this page
get_term_field( string $field, int|WP_Term $term, string $taxonomy = '', string $context = 'display' ): string|int|null|WP_Error
Gets sanitized term field.
Description
The function is for contextual reasons and for simplicity of usage.
See also
Parameters
$fieldstring Required-
Term field to fetch.
$termint|WP_Term Required-
Term ID or object.
$taxonomystring Optional-
Taxonomy name.
Default:
'' $contextstring Optional-
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'
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.
Source
File: wp-includes/taxonomy.php. View all references
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
Uses
| Uses | Description |
|---|---|
| sanitize_term_field() wp-includes/taxonomy.php | Sanitizes the field value in the term based on the context. |
| get_term() wp-includes/taxonomy.php | Gets all term data from database by term ID. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Menu_Items_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares links for the request. |
| WP_REST_Menu_Items_Controller::prepare_item_for_database() wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post for create or update. |
| WP_Customize_Nav_Menu_Item_Setting::get_original_title() wp-includes/customize/class-wp-customize-nav-menu-item-setting.php | Get original title. |
| term_description() wp-includes/category-template.php | Retrieves term description. |
| wp_setup_nav_menu_item() wp-includes/nav-menu.php | Decorates a menu item object with the shared navigation menu item properties. |
| wp_update_nav_menu_item() wp-includes/nav-menu.php | Saves the properties of a menu item or create a new one. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_term_field