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 .'';
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With