I know I can get a categories ID by calling get_cat_ID(‘category-slug’), however, what is the method to call to determine if a category exists by ID when you don’t know the slug?
In other words, I need to determine if category id 1 exists. What’s the function for this?
Can I just use if(get_category(1)) {//do something?}
There is
category_exists()
function, but it seems to be for internal use in admin so you can tryterm_exists()
instead.take a look at get_term_by
you can define by what you want to look for the term using slug,ID or name
so you can call it like this in your case: