get_term_field() - WordPress 函数参考中文文档

返回介绍

get_term_field()

发布于 2017-09-11 字数2605 浏览 900 评论 0

get_term_field( string $field,  int|WP_Term $term,  string $taxonomy = '',  string $context = 'display' )

Get sanitized Term field.


描述

The function is for contextual reasons and for simplicity of usage.


参数

$field

(string)
(Required)
Term field to fetch.

$term

(int|WP_Term)
(Required)
Term ID or object.

$taxonomy

(string)
(Optional)
Taxonomy Name.

Default value: ”

$context

(string)
(Optional)
default is display. Look at sanitize_term_field() for available options.

Default value: ‘display’


返回值

(string|int|null|WP_Error) Will return an empty string if $term is not an object or if $field is not set in $term.


源代码

File: wp-includes/taxonomy.php

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 );
}

更新日志

Version 描述
4.4.0 The $taxonomy parameter was made optional. $term can also now accept a WP_Term object.
2.3.0 Introduced.

相关函数

Uses

  • wp-includes/taxonomy.php:
    sanitize_term_field()
  • wp-includes/taxonomy.php:
    get_term()
  • wp-includes/load.php:
    is_wp_error()

Used By

  • wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:
    WP_Customize_Nav_Menu_Item_Setting::get_original_title()
  • wp-admin/includes/class-walker-nav-menu-edit.php:
    Walker_Nav_Menu_Edit::start_el()
  • wp-includes/category-template.php:
    term_描述()
  • wp-includes/nav-menu.php:
    wp_setup_nav_menu_item()
  • wp-includes/nav-menu.php:
    wp_update_nav_menu_item()

User Contributed Notes

上一篇:get_term_feed_link()

下一篇:get_term_link()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!