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
$postint|WP_Postoptional
Post ID or WP_Post object. Default is global $post.Default: 0
$argsarrayoptional
Arguments about how to format the list of taxonomies. Default empty array.Default: array()
$templatestringdefault: is the term name linked to its archive
Template for displaying a taxonomy label and list of terms. Default is "Label: Terms." @type string $term_template Template for displaying a single term in the list.
Return
string[]
List of taxonomies.
Uses · 10
get_post()Retrieves post data given a post ID or post object.
wp_parse_args()Merges user defined arguments into defaults array.
get_object_taxonomies()Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
get_taxonomy()Retrieves the taxonomy object of $taxonomy.
4866functionget_the_taxonomies($post=0,$args=array()){4867$post=get_post($post);48684869$args=wp_parse_args(4870$args,4871array(4872/* translators: %s: Taxonomy label, %l: List of terms formatted as per $term_template. */4873'template'=>__('%s: %l.'),4874'term_template'=>'<a href="%1$s">%2$s</a>',4875)4876);48774878$taxonomies=array();48794880if(!$post){4881return$taxonomies;4882}48834884foreach(get_object_taxonomies($post)as$taxonomy){4885$t=(array)get_taxonomy($taxonomy);4886if(empty($t['label'])){4887$t['label']=$taxonomy;4888}4889if(empty($t['args'])){4890$t['args']=array();4891}4892if(empty($t['template'])){4893$t['template']=$args['template'];4894}4895if(empty($t['term_template'])){4896$t['term_template']=$args['term_template'];4897}48984899$terms=get_object_term_cache($post->ID,$taxonomy);4900if(false===$terms){4901$terms=wp_get_object_terms($post->ID,$taxonomy,$t['args']);4902}4903$links=array();49044905foreach($termsas$term){4906$links[]=wp_sprintf($t['term_template'],esc_attr(get_term_link($term)),$term->name);4907}4908if($links){4909$taxonomies[$taxonomy]=wp_sprintf($t['template'],$t['label'],$links,$terms);4910}4911}4912return$taxonomies;4913}
History
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/taxonomy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.