WordPress Code Snippets

A fresh mix of code snippets and tutorials

WordPress Get Category ID from Slug


Quick WordPress snippet for getting the category ID from the category slug.

Don’t blink or you’ll miss it:

Here we pass the $slug to WordPress’ get_category_by_slug() function. That gives us an object of useful category data, including the ID, which we then call directly:

$catID = $cat->term_id;

To see what else is available try adding the following to your script:


It’s just good times.

Learn more

WordPress Themes In Depth

Show Support

Like our new Facebook Page to show support!