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.
4787functionget_the_taxonomies($post=0,$args=array()){4788$post=get_post($post);47894790$args=wp_parse_args(4791$args,4792array(4793/* translators: %s: Taxonomy label, %l: List of terms formatted as per $term_template. */4794'template'=>__('%s: %l.'),4795'term_template'=>'<a href="%1$s">%2$s</a>',4796)4797);47984799$taxonomies=array();48004801if(!$post){4802return$taxonomies;4803}48044805foreach(get_object_taxonomies($post)as$taxonomy){4806$t=(array)get_taxonomy($taxonomy);4807if(empty($t['label'])){4808$t['label']=$taxonomy;4809}4810if(empty($t['args'])){4811$t['args']=array();4812}4813if(empty($t['template'])){4814$t['template']=$args['template'];4815}4816if(empty($t['term_template'])){4817$t['term_template']=$args['term_template'];4818}48194820$terms=get_object_term_cache($post->ID,$taxonomy);4821if(false===$terms){4822$terms=wp_get_object_terms($post->ID,$taxonomy,$t['args']);4823}4824$links=array();48254826foreach($termsas$term){4827$links[]=wp_sprintf($t['term_template'],esc_attr(get_term_link($term)),$term->name);4828}4829if($links){4830$taxonomies[$taxonomy]=wp_sprintf($t['template'],$t['label'],$links,$terms);4831}4832}4833return$taxonomies;4834}
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 6.7.7 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.