get_term_field

函式
get_term_field ( $field, $term, $taxonomy = '', $context = 'display' )
引數
  • (string) $field Term field to fetch.
    Required:
  • (int|WP_Term) $term Term ID or object.
    Required:
  • (string) $taxonomy Optional. Taxonomy name. Default empty.
    Required:
    Default: (empty)
  • (string) $context Optional. How to sanitize term fields. Look at sanitize_term_field() for available options. Default 'display'.
    Required:
    Default: '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.
相關
  • sanitize_term_field()
定義位置
相關方法
get_post_fieldget_term_childrenget_term_feed_linkget_the_id_get_term_children
引入
2.3.0
棄用
-

get_term_field: 這個函式檢索術語(類別、標籤等)物件的一個特定欄位。它需要三個引數:術語物件或ID,要檢索的欄位,以及是否返回單個值或一個陣列值。它返回請求的術語欄位值。

獲得經過淨化的術語欄位。

該函式是出於上下文的原因和使用的簡單性。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >