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.
4824functionget_the_taxonomies($post=0,$args=array()){4825$post=get_post($post);48264827$args=wp_parse_args(4828$args,4829array(4830/* translators: %s: Taxonomy label, %l: List of terms formatted as per $term_template. */4831'template'=>__('%s: %l.'),4832'term_template'=>'<a href="%1$s">%2$s</a>',4833)4834);48354836$taxonomies=array();48374838if(!$post){4839return$taxonomies;4840}48414842foreach(get_object_taxonomies($post)as$taxonomy){4843$t=(array)get_taxonomy($taxonomy);4844if(empty($t['label'])){4845$t['label']=$taxonomy;4846}4847if(empty($t['args'])){4848$t['args']=array();4849}4850if(empty($t['template'])){4851$t['template']=$args['template'];4852}4853if(empty($t['term_template'])){4854$t['term_template']=$args['term_template'];4855}48564857$terms=get_object_term_cache($post->ID,$taxonomy);4858if(false===$terms){4859$terms=wp_get_object_terms($post->ID,$taxonomy,$t['args']);4860}4861$links=array();48624863foreach($termsas$term){4864$links[]=wp_sprintf($t['term_template'],esc_attr(get_term_link($term)),$term->name);4865}4866if($links){4867$taxonomies[$taxonomy]=wp_sprintf($t['template'],$t['label'],$links,$terms);4868}4869}4870return$taxonomies;4871}
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.0.4 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.