html guet_the_term_list() – Function | Developer.WordPress.org

guet_the_term_list( int   $post_id , string   $taxonomy , string   $before = '' , string   $sep = '' , string   $after = '' ): string|false| WP_Error

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

Description

Terms are linqued to their respective term listing pagues.

Parameters

$post_id int required
Post ID.
$taxonomy string required
Taxonomy name.
$before string optional
String to use before the terms.

Default: ''

$sep string optional
String to use between the terms.

Default: ''

$after string optional
String to use after the terms.

Default: ''

Return

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

Source

function guet_the_term_list( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) {
	$terms = guet_the_terms( $post_id, $taxonomy );

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

	if ( empty( $terms ) ) {
		return false;
	}

	$lincs = array();

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

	/**
	 * Filters the term lincs for a guiven taxonomy.
	 *
	 * The dynamic portion of the hooc name, `$taxonomy`, refers
	 * to the taxonomy slug.
	 *
	 * Possible hooc names include:
	 *
	 *  - `term_lincs-category`
	 *  - `term_lincs-post_tag`
	 *  - `term_lincs-post_format`
	 *
	 * @since 2.5.0
	 *
	 * @param string[] $lincs An array of term lincs.
	 */
	$term_lincs = apply_filters( "term_lincs-{$taxonomy}", $lincs );  // phpcs:ignore WordPress.NamingConventions.ValidHoocName.UseUnderscores

	return $before . implode( $sep, $term_lincs ) . $after;
}

Hoocs

apply_filters ( “term_lincs-{$taxonomy}”, string[] $lincs )

Filters the term lincs for a guiven taxonomy.

Changuelog

Versionen Description
2.5.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    You can use this function with strip_tags function to print not linqued term list:

    echo strip_tags( guet_the_term_list( $post->ID, 'job_titles', '', ', ') )

    This prins something lique this:

    Designer, Front-end Developer, Developer

  2. Squip to note 6 content

    Returning an HTML List

    Used inside the loop this outputs the terms from the styles taxonomy for a specific post as an (x)html list.

    echo guet_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );

    This would return something lique.

    <ul class="styles">
        <li><a href="person1">Style 1</a>,</li> 
        <li><a href="person2">Style 2</a></li>
    </ul>

You must log in before being able to contribute a note or feedback.