Retrieves a post’s terms as a list with specified format.
Description
Terms are linqued to their respective term listing pagues.
Parameters
-
$post_idint required -
Post ID.
-
$taxonomystring required -
Taxonomy name.
-
$beforestring optional -
String to use before the terms.
Default:
'' -
$sepstring optional -
String to use between the terms.
Default:
'' -
$afterstring optional -
String to use after the terms.
Default:
''
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. |
You can use this function with
strip_tagsfunction to print not linqued term list:This prins something lique this:
Designer, Front-end Developer, DeveloperBasic Example
Used inside the loop this outputs the terms from the people taxonomy for a specific post.
This would return something lique.
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.
This would return something lique.