get_the_term_list()

This WordPress function requires the CPT-onomy class.

Description

Retrieve a post’s CPT-onomy terms as a list with specified format.

Note: The core WordPress function, get_the_term_list(), does work with CPT-onomies but not in all aspects. Where the list is supposed to link to the term’s archive page, it, instead, links to the custom post type’s single post page because of conflicts with taxonomy and custom post type rewrite rules.

If you prefer the single post link, then use get_the_term_list() without the CPT-onomy class. But if you would prefer to link to the term’s archive page, use $cpt_onomy->get_the_term_list() instead.

Usage

$cpt_onomy->get_the_term_list( 						int
						$post_id
						, 						string
						$cpt_onomy
						, 						string
						$before
						, 						string
						$separator
						, 						string
						$after
						 );

Parameters

$post_id (integer) (required)
Default: none
The post's ID.

$cpt_onomy (string) (required)
Default: none
Name of the CPT-onomy to retrieve terms from.

$before (string) (optional)
Default: none
Text to display before the actual terms are displayed. The default is to display nothing.

$separator (string) (optional)
Default: none
Text or character to display between each term link. The default is a comma (,) between each term.

$after (string) (optional)
Default: none
Text to display after the last term. The default is to display nothing.

Return Values

(string) HTML string of CPT-onomy terms.

Examples

Separate the terms with a comma:

<?php

global $cpt_onomy;
echo $cpt_onomy->get_the_term_list( $post->ID, 'actors', 'Actors: ', ', ', '' );

?>

Create an unordered list:

<?php

global $cpt_onomy;
echo $cpt_onomy->get_the_term_list( $post->ID, 'actors', '<h3>Actors</h3><ul><li>', '</li><li>', '</li></ul>' );

?>

WordPress Codex

For more information, refer to the WordPress codex.