$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Display the taxonomy name of the current term|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Display the taxonomy name of the current term

matteradmin10PV0评论

I have a hierarchical taxonomy with lots of terms in hierarchical order.

No matter what term i'm viewing I'd like to be able to display the custom taxonomy name (as per what i've registered it as singular_name) on that page. I've searched here and the WP forums to death but had no luck.

I found this but it only displays the slug, not the name...

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );    
echo $term->taxonomy; 

I have a hierarchical taxonomy with lots of terms in hierarchical order.

No matter what term i'm viewing I'd like to be able to display the custom taxonomy name (as per what i've registered it as singular_name) on that page. I've searched here and the WP forums to death but had no luck.

I found this but it only displays the slug, not the name...

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );    
echo $term->taxonomy; 
Share Improve this question edited Jan 26, 2019 at 5:54 Pete asked Jan 26, 2019 at 5:42 PetePete 1,0582 gold badges14 silver badges40 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

get_taxonomy( $taxonomy_name ) will give you an object containing all of the taxonomy metadata:

$queried_object = get_queried_object();
$this_tax = get_taxonomy( $queried_object->taxonomy );
echo $this_tax->labels->singular_name;

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far