I’m trying to get category ID of the current archive displayed.
I tried:
// category (can be a parent category)
$current_cat_ID = get_query_var('cat');
//
print_r ($current_cat_ID);
It doesn’t print anything…
I’m trying to get category ID of the current archive displayed.
I tried:
// category (can be a parent category)
$current_cat_ID = get_query_var('cat');
//
print_r ($current_cat_ID);
It doesn’t print anything…
You must be logged in to post a comment.
you can use
get_queried_object()
A little bit faster than receiving the object and echo the term ID afterwards is to directly use
get_queried_object_id()
.If you want to fecth in category page,you can get id of current category by:
If you want to get category id of any particular category on any page, you can try using below code: