get_the_term_list( int $post_id, string $taxonomy, string $before = '', string $sep = '', string $after = '' )
Retourne les termes d'un poste sous forme de liste au format spécifié.
Paramètres
$post_id
(int) (Requis) Id du poste.
$taxonomy
(string) (Requis) Nom de la taxonomie.
$before
(string) (Optionnel) Chaîne à utiliser avant les termes.
Valeur par défaut : ''
$sep
(string) (Optionnel) Chaîne à utiliser entre les termes.
Valeur par défaut : ''
$after
(string) (Optionnel) Chaîne à utiliser après les termes.
Valeur par défaut : ''
Retourne
(string | false | WP_Error) Une liste de termes, false s'il n'y a aucuns termes ou WP_Error si échec.
Structure de la fonction get_the_term_list()
Définie dans le fichier wp-includes/category-template.php à la ligne 1316 :
function get_the_term_list( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) {
$terms = get_the_terms( $post_id, $taxonomy );
if ( is_wp_error( $terms ) ) {
return $terms;
}
if ( empty( $terms ) ) {
return false;
}
$links = array();
foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) ) {
return $link;
}
$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
}
/**
* Filters the term links for a given taxonomy.
*
* The dynamic portion of the filter name, `$taxonomy`, refers
* to the taxonomy slug.
*
* @since 2.5.0
*
* @param string[] $links An array of term links.
*/
$term_links = apply_filters( "term_links-{$taxonomy}", $links ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
return $before . join( $sep, $term_links ) . $after;
}
Fonctions et Hook utilisés par get_the_term_list()
term_links-{$taxonomy}
Filtre les liens de terme pour une taxonomie donnée.
get_the_terms()
Retourne les termes d'une taxonomie attachés à un poste.
esc_url()
Vérifie et nettoie une URL.
get_term_link()
Génère un permalien pour l'archive d'un terme.
apply_filters()
Appel les fonctions qui ont été attaché à un filtre (hook).
is_wp_error()
Vérifie si la variable est une erreur WordPress.
Où trouver la fonction get_the_term_list()
dans le CMS Wordpress
Exemples
Sources
Codex Wordpress : get_the_term_list()
Autres fonctions dans le même fichier : wp-includes/category-template.php