get_term_field()

最后更新于:2021-11-27 00:56:14

get_term_field( string$field, int|GC_Term$term, string$taxonomy=”, string$context=’display’)

Get sanitized Term field.

参数

$field

(string) (Required) Term field to fetch.

$term

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

$taxonomy

(string) (Optional) Taxonomy Name.

Default value: ”

$context

(string) (Optional) How to sanitize term fields. Look at sanitize_term_field() for available options.

Default value: ‘display’

响应

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

源文件

文件: gc-includes/taxonomy.php

function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
	$term = get_term( $term, $taxonomy );
	if ( is_gc_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 );
}