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.
4798functionget_the_taxonomies($post=0,$args=array()){4799$post=get_post($post);48004801$args=wp_parse_args(4802$args,4803array(4804/* translators: %s: Taxonomy label, %l: List of terms formatted as per $term_template. */4805'template'=>__('%s: %l.'),4806'term_template'=>'<a href="%1$s">%2$s</a>',4807)4808);48094810$taxonomies=array();48114812if(!$post){4813return$taxonomies;4814}48154816foreach(get_object_taxonomies($post)as$taxonomy){4817$t=(array)get_taxonomy($taxonomy);4818if(empty($t['label'])){4819$t['label']=$taxonomy;4820}4821if(empty($t['args'])){4822$t['args']=array();4823}4824if(empty($t['template'])){4825$t['template']=$args['template'];4826}4827if(empty($t['term_template'])){4828$t['term_template']=$args['term_template'];4829}48304831$terms=get_object_term_cache($post->ID,$taxonomy);4832if(false===$terms){4833$terms=wp_get_object_terms($post->ID,$taxonomy,$t['args']);4834}4835$links=array();48364837foreach($termsas$term){4838$links[]=wp_sprintf($t['term_template'],esc_attr(get_term_link($term)),$term->name);4839}4840if($links){4841$taxonomies[$taxonomy]=wp_sprintf($t['template'],$t['label'],$links,$terms);4842}4843}4844return$taxonomies;4845}
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.8.8 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.