Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_term_field ›

Seit2.3.0
Veraltetn/v
get_term_field ( $field, $term, $taxonomy = '', $context = 'display' )
Parameter: (4)
  • (string) $field Term field to fetch.
    Erforderlich: Ja
  • (int|WP_Term) $term Term ID or object.
    Erforderlich: Ja
  • (string) $taxonomy Optional. Taxonomy Name. Default empty.
    Erforderlich: Nein
    Standard: (leer)
  • (string) $context Optional, default is display. Look at sanitize_term_field() for available options.
    Erforderlich: Nein
    Standard: 'display'
Siehe:
Gibt zurück:
  • (string|int|null|WP_Error) Will return an empty string if $term is not an object or if $field is not set in $term.
Definiert in:
Codex:
Changelog:
  • 4.4.0

Get sanitized Term field.

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



Quellcode

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