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.
4820functionget_the_taxonomies($post=0,$args=array()){4821$post=get_post($post);48224823$args=wp_parse_args(4824$args,4825array(4826/* translators: %s: Taxonomy label, %l: List of terms formatted as per $term_template. */4827'template'=>__('%s: %l.'),4828'term_template'=>'<a href="%1$s">%2$s</a>',4829)4830);48314832$taxonomies=array();48334834if(!$post){4835return$taxonomies;4836}48374838foreach(get_object_taxonomies($post)as$taxonomy){4839$t=(array)get_taxonomy($taxonomy);4840if(empty($t['label'])){4841$t['label']=$taxonomy;4842}4843if(empty($t['args'])){4844$t['args']=array();4845}4846if(empty($t['template'])){4847$t['template']=$args['template'];4848}4849if(empty($t['term_template'])){4850$t['term_template']=$args['term_template'];4851}48524853$terms=get_object_term_cache($post->ID,$taxonomy);4854if(false===$terms){4855$terms=wp_get_object_terms($post->ID,$taxonomy,$t['args']);4856}4857$links=array();48584859foreach($termsas$term){4860$links[]=wp_sprintf($t['term_template'],esc_attr(get_term_link($term)),$term->name);4861}4862if($links){4863$taxonomies[$taxonomy]=wp_sprintf($t['template'],$t['label'],$links,$terms);4864}4865}4866return$taxonomies;4867}
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.9.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.