In this article we will walk through How to check the WordPress Category has been already exists or not using the WordPress Function.
I am going to use term_exists() function.
Here is the syntax: term_exists($slug, $taxonomy_name, $parent);
$slug = >It denotes the category slug which you want to find in the existing list of category.
$taxonomy_name => It denotes the taxonomy name where the slug exists
$parent => It can be optional. Where we can pass the parent category id.
Here is the reference code.
$slug = 'test-cat'; $taxonomy_name = 'category'; $parent = 0; $id = term_exists($slug, $taxonomy_name, $parent); if ($id) { return $id; }
I hope this will work for you. Kindly share your feedback through comments.
Thanks