How to get Current taxonomy term id on WordPress

If you created a taxonomy.php page in my wordpress template folder, You would like to get the current term id for a function. How can You get this?

This snippet will only returns the term slug

get_query_var('taxonomy')

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 .''; 
?>

SeeĀ wp_get_post_terms(), you’d do something like so:

global $post;
$terms = wp_get_post_terms( $post->ID, 'YOUR_TAXONOMY_NAME',array('fields' => 'ids') );

print_r($terms);

Written By:

Sarmad Gardezi A blog scientist by Mind and a Passionate Blogger by heart. Sarmad is Freelancer, Entrepreneur and Google Apps Scripts Developer from Islamabad, Pakistan.

Subscribe to Email Newsletter