返回介绍

get_term_field()

发布于 2017-09-11 00:22:02 字数 2610 浏览 1060 评论 0 收藏 0

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

Get sanitized Term field.


description

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

更新日志

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

相关函数

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_description()
  • wp-includes/nav-menu.php: wp_setup_nav_menu_item()
  • wp-includes/nav-menu.php: wp_update_nav_menu_item()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文