Get ID of Current Category – WordPress

Getting the ID of the current category in WordPress is actually quite simple. This will work in category archive pages or anywhere a category has been queried.

We are going to use get_queried_object() to accomplish this task. The following script will get all the information about our queried object and put it in an array, $category. Then we are simply getting the term_id from that array and echoing it.

Get Current Category ID

Just place that code in any template file where a category has been queried, such as category archive pages, and you will be able to get the category id no problem. Another fun trick is if you are looking to display future posts in your query.

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.

5 Comments on “Get ID of Current Category – WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *