Get the term ID on custom category or taxonomy page

WordPress introduce a custom taxonomy in the WordPress 2.3 Version but they start extreme using this from the Version 2.9. Taxonomy is an option to group some posts in one or multiple. Basically WordPress has already provided 3 types taxonomy:

  • Category
  • Tag
  • Link

Sometimes we need to create custom post type and then we also add some taxonomy options in that custom post like product is custom post type and product category is custom taxonomy. So we need to create a custom taxonomy template also to achieve our goal.

For this WordPress provides a function get_queried_object().

$queried_object = get_queried_object();

$term_id = $queried_object->term_id;