wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



get_term_field › WordPress Function

Depuis2.3.0
Dépréciéen/a
get_term_field ( $field, $term, $taxonomy = '', $context = 'display' )
Paramètres: (4)
  • (string) $field Term field to fetch.
    Requis: Oui
  • (int|WP_Term) $term Term ID or object.
    Requis: Oui
  • (string) $taxonomy Optional. Taxonomy name. Default empty.
    Requis: Non
    Défaut: (vide)
  • (string) $context Optional. How to sanitize term fields. Look at sanitize_term_field() for available options. Default 'display'.
    Requis: Non
    Défaut: 'display'
Voir:
Retourne:
  • (string|int|null|WP_Error) Will return an empty string if $term is not an object or if $field is not set in $term.
Défini(e) dans:
Codex:
Changelog:
  • 4.4.0

Gets sanitized term field.

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


Source

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