get current term id

To get the current term ID in WordPress, you can follow the steps below:

  1. First, you need to check if you are currently on a term archive page. To do this, you can use the is_tax() function. This function checks if the current page is a taxonomy archive page.

  2. Next, you need to get the current term object. You can use the get_queried_object() function to retrieve the current term object. This function returns the currently queried object in the WordPress loop.

  3. Once you have the term object, you can access its ID property using the term_id attribute. This will give you the ID of the current term.

Here is the code snippet that demonstrates these steps:

if (is_tax()) {
    $current_term = get_queried_object();
    $current_term_id = $current_term->term_id;
    // Now you have the current term ID
}

By following these steps, you can easily retrieve the current term ID in WordPress.