Wordpress: How do I get a taxonomic name in taxonomy.php?

I can show the term taxonomy on the taxonomy page, but how can I get the taxonomy or display the taxonomy on the page.

for example, when I have a taxonomy called “fruit” and I click on a term with fruit called “lemons”. How do I display both lemons and fruits on the taxonomy terms page?

Just find the equivalent of receiving. thanks!

+8
wordpress taxonomy
source share
8 answers

It’s too complicated for my taste, but here it is:

$term = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; 
+6
source share

If you check $wp_query->get_queried_object() on the taxonomy page, it will contain the term object that has a link to the taxonomy identifier (in my example, this is replymc_people ). Pass this get_taxonomy and you will get the full taxonomy object.

 object(stdClass)[325] public 'term_id' => string '113' (length=3) public 'name' => string 'Jef Staes' (length=9) public 'slug' => string 'jef-staes' (length=9) public 'term_group' => string '0' (length=1) public 'term_taxonomy_id' => string '107' (length=3) public 'taxonomy' => string 'replymc_people' (length=14) public 'description' => string '' (length=0) public 'parent' => string '0' (length=1) public 'count' => string '3' (length=1) 
+5
source share

Possible Solution:

 $taxonomy = get_queried_object(); echo $taxonomy->name; 
+5
source share
 get_query_var('taxonomy'); 

Only this should work.

+4
source share

I know that this is a resolved problem, but here is another way to get the name of the taxonomy, which, in my opinion, is clean. For those who have found it now, like me. I like to raise awareness of global variables in wordpress.

 $tax_term = $wp_query->query_vars['tax_name']; 
+3
source share

I know that this is answered, but for those who may appear on this page when searching ...

 global $taxonomy,$term; 

$ Taxonomy will now contain your taxonomy name ("fruit" from the OP example) and your taxonomic name ("lemon" from the OP example).

+3
source share

You can get specific data about terms / taxonomy, such as name, description, etc. at taxonomy.php

 <?php $termid = get_queried_object()->term_id; $term = get_term( $termid, 'taxonomy-name' ); echo $term->name.'<br>'; echo $term->description; ?> 
+1
source share

Someone can go this route (I did) so ...

 $tax = $wp_query->get_queried_object(); $tax_term = $tax->name; $tax = get_taxonomy($tax->taxonomy); $taxonomy = $tax->label; echo "$tax_term are $taxonomy"; 

returns "Lemons are fruits."

I would like to know one insert for this, but I don’t think there is one, you need parts of two objects.

0
source share

All Articles