Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current taxonomy term ID (not the slug) in WordPress?

People also ask

How do I find the taxonomy of a slug in WordPress?

WordPress does provide a function to get the taxonomy information from its slug. The slug is not the same as the name of the taxonomy. Your example only works because they happen to be equal in this particular case. get_taxonomy takes a taxonomy name, not a slug.


Nevermind! I found it :)

get_queried_object()->term_id;

Simple and easy!

get_queried_object_id()

Here's the whole code snippet needed:

$queried_object = get_queried_object();
$term_id = $queried_object->term_id;

Use following code

This will print your current taxonomy name and description(optional)

<?php 
   $tax = $wp_query->get_queried_object();
   echo ''. $tax->name . '';
   echo "<br>";
   echo ''. $tax->description .''; 
?>