the_terms() WordPress Function

The the_terms() function is used to display the terms associated with a post.

the_terms( int $post_id, string $taxonomy, string $before = '', string $sep = ', ', string $after = '' ) #

Displays the terms for a post in a list.


Parameters

$post_id

(int)(Required)Post ID.

$taxonomy

(string)(Required)Taxonomy name.

$before

(string)(Optional) String to use before the terms.

Default value: ''

$sep

(string)(Optional) String to use between the terms.

Default value: ', '

$after

(string)(Optional) String to use after the terms.

Default value: ''


Top ↑

Return

(void|false) Void on success, false on failure.


Top ↑

Source

File: wp-includes/category-template.php

function the_terms( $post_id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
	$term_list = get_the_term_list( $post_id, $taxonomy, $before, $sep, $after );

	if ( is_wp_error( $term_list ) ) {
		return false;
	}

	/**
	 * Filters the list of terms to display.
	 *
	 * @since 2.9.0
	 *
	 * @param string $term_list List of terms to display.
	 * @param string $taxonomy  The taxonomy name.
	 * @param string $before    String to use before the terms.
	 * @param string $sep       String to use between the terms.
	 * @param string $after     String to use after the terms.
	 */
	echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after );
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.