A WordPress-centric search engine for devs and theme authors



get_the_term_list ›

Since2.5.0
Deprecatedn/a
get_the_term_list ( $id, $taxonomy, $before = '', $sep = '', $after = '' )
Parameters: (5)
  • (int) $id Post ID.
    Required: Yes
  • (string) $taxonomy Taxonomy name.
    Required: Yes
  • (string) $before Optional. Before list.
    Required: No
    Default: (empty)
  • (string) $sep Optional. Separate items using this.
    Required: No
    Default: (empty)
  • (string) $after Optional. After list.
    Required: No
    Default: (empty)
Returns:
  • (string|bool|WP_Error) A list of terms on success, false if there are no terms, WP_Error on failure.
Defined at:
Codex:

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



Source

function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
	$terms = get_the_terms( $id, $taxonomy );

	if ( is_wp_error( $terms ) )
		return $terms;

	if ( empty( $terms ) )
		return false;

	foreach ( $terms as $term ) {
		$link = get_term_link( $term, $taxonomy );
		if ( is_wp_error( $link ) )
			return $link;
		$term_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
	}

	/**
	 * Filter 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 array $term_links An array of term links.
	 */
	$term_links = apply_filters( "term_links-$taxonomy", $term_links );

	return $before . join( $sep, $term_links ) . $after;
}