get_the_term_list() – Retrieves a post’s terms as a list with specified format.

You appear to be a bot. Output may be restricted

Description

Retrieves a post's terms as a list with specified format.

Terms are linked to their respective term listing pages.

Usage

$string|false|WP_Error = get_the_term_list( $post_id, $taxonomy, $before, $sep, $after );

Parameters

$post_id
( int ) required – Post ID.
$taxonomy
( string ) required – Taxonomy name.
$before
( string ) optional – Optional. String to use before the terms. Default empty.
$sep
( string ) optional – Optional. String to use between the terms. Default empty.
$after
( string ) optional – Optional. String to use after the terms. Default empty.

Returns

string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.

Source

File name: wordpress/wp-includes/category-template.php


Lines:

1 to 43 of 43
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 hook name, `$taxonomy`, refers
 * to the taxonomy slug.
 *
 * Possible hook names include:
 *
 *  - `term_links-category`
 *  - `term_links-post_tag`
 *  - `term_links-post_format`
 *
 * @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 . implode( $sep, $term_links ) . $after;
}
 

 View on GitHub View on Trac