the_terms( int $post_id, string $taxonomy, string $before = '', string $sep = ', ', string $after = '' )
Affiche la liste des termes d'un poste.
Paramètres
$post_id(int)requisId du poste.
$taxonomy(string)requisNom de la taxonomie.
$before(string)optionnelMots à mettre avant la liste des termes.
Valeur par défaut : ''
$sep(string)optionnelMot à mettre entre chaque terme.
Valeur par défaut : ', '
$after(string)optionnelMots à mettre après la liste des termes.
Valeur par défaut : ''
Retourne
(void|false) Affiche la liste si succès, false si échec.
Déclaration et structure de la fonction the_terms()
the_terms() est déclarée dans le fichier wp-includes/category-template.php à la ligne 1457 :
function the_terms( $post_id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
$term_list = get_the_term_list( $post_id, $taxonomy, $before, $sep, $after );
if ( is_wp_error( $term_list ) ) {
return false;
}
/**
* Filters the list of terms to display.
*
* @since 2.9.0
*
* @param string $term_list List of terms to display.
* @param string $taxonomy The taxonomy name.
* @param string $before String to use before the terms.
* @param string $sep String to use between the terms.
* @param string $after String to use after the terms.
*/
echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after );
}
Fonctions utilisées par the_terms()
get_the_term_list()Retourne les termes d'un poste sous forme de liste au format spécifié.
apply_filters()Appel les fonctions qui ont été attaché à un filtre (hook).
is_wp_error()Vérifie si la variable est une erreur WordPress.
Hook utilisé par the_terms()
the_termsFiltre la liste de termes à afficher.
Où est utilisée la fonction the_terms()
dans le CMS WordPress
Exemple
the_terms( $post->ID, 'category', 'Categories : ', ' / ' );
// Affichera :
Categories : TV / Speaker / Monitor
Sources
Codex WordPress : the_terms()
Autres fonctions dans le même fichier : wp-includes/category-template.php