WordPress at a glance

get_the_term_list() WP 1.0

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

Is the basis for: get_the_tag_list(), the_terms()
Works based on: get_the_terms()
✈ 1 time = 0.004471s = very slow | 50000 times = 5.31s = fast PHP 7.1.2, WP 4.7.3
Hooks from function:
Return

String/false/WP_Error. A list of terms on success, false if there are no terms, WP_Error on failure.

Usage

get_the_term_list( $id, $taxonomy, $before, $sep, $after );
$id(int) (required)
Post ID.
$taxonomy(string) (required)
Taxonomy name.
$before(string)
Before list.
Default: ''
$sep(string)
Separate items using this.
Default: ''
$after(string)
After list.
Default: ''

Code of get_the_term_list: wp-includes/category-template.php VER 4.9.8

<?php
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;

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

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

Related Functions

From tag: List (wp_list)

More from tag: Term (taxonomies terms)

More from category: For posts

More from Template Tags: Taxonomies (category, tag)

No comments
    Hello, !     Log In . Register