Summery Summery
Retrieve all taxonomies associated with a post.
Syntax Syntax
Description Description
This function can be used within the loop. It will also return an array of the taxonomies with links to the taxonomy and name.
Parameters Parameters
- $post
-
(Optional) Post ID or WP_Post object. Default is global $post.
- $args
-
(Optional) Arguments about how to format the list of taxonomies.
- 'template'
(string) Template for displaying a taxonomy label and list of terms. Default is "Label: Terms." - 'term_template'
(string) Template for displaying a single term in the list. Default is the term name linked to its archive.
Default value: array()
- 'template'
Return Return
(array) List of taxonomies.
Source Source
File: wp-includes/taxonomy.php
$slug = $term->slug; $t = get_taxonomy( $taxonomy ); if ( empty( $termlink ) ) { if ( 'category' === $taxonomy ) { $termlink = '?cat=' . $term->term_id; } elseif ( $t->query_var ) { $termlink = "?$t->query_var=$slug"; } else { $termlink = "?taxonomy=$taxonomy&term=$slug"; } $termlink = home_url( $termlink ); } else { if ( $t->rewrite['hierarchical'] ) { $hierarchical_slugs = array(); $ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' ); foreach ( (array) $ancestors as $ancestor ) { $ancestor_term = get_term( $ancestor, $taxonomy ); $hierarchical_slugs[] = $ancestor_term->slug; } $hierarchical_slugs = array_reverse( $hierarchical_slugs ); $hierarchical_slugs[] = $slug; $termlink = str_replace( "%$taxonomy%", implode( '/', $hierarchical_slugs ), $termlink ); } else { $termlink = str_replace( "%$taxonomy%", $slug, $termlink ); } $termlink = home_url( user_trailingslashit( $termlink, 'category' ) ); } // Back compat filters. if ( 'post_tag' === $taxonomy ) { /** * Filters the tag link. * * @since 2.3.0 * @since 2.5.0 Deprecated in favor of {@see 'term_link'} filter. * @since 5.4.1 Restored (un-deprecated). * * @param string $termlink Tag link URL. * @param int $term_id Term ID. */ $termlink = apply_filters( 'tag_link', $termlink, $term->term_id ); } elseif ( 'category' === $taxonomy ) { /** * Filters the category link. *
Advertisement
Changelog Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |