WordPress at a glance

get_the_term_list() WP 1.0

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

Terms are linked to their respective term listing pages.

Возвращает

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

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 the function

Usage

get_the_term_list( $post_id, $taxonomy, $before, $sep, $after );
$post_id(int) (required)
Post ID.
$taxonomy(string) (required)
Taxonomy name.
$before(string)
String to use before the terms.
Default: ''
$sep(string)
String to use between the terms.
Default: ''
$after(string)
String to use after the terms.
Default: ''

Список изменений

С версии 2.5.0 Введена.

Code of get_the_term_list() WP 5.5.1

wp-includes/category-template.php
<?php
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;
}

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)

vladlu 100vlad.lu
Editors: kama 100
No comments
    Log In . Register