I'm trying to get the current ID of the category page I'm viewing.
I had checked the_category_ID
But this echo'd my result when I used
<?php $catID = the_category_ID(); ?>
Is there a way to get it to return the value to the variable so its hidden?
Use get_the_category() and then do a print_r() to see what it outputs. It should output an array, and in that case follow the code that pallavi put in the answer.
The current category ID is in the global $cat
variable, when you are in a category page.
You can test it with:
<?php echo "Current Category ID is: " . $cat ;?>
when you are in for example this page http://example.com/category/test
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