How do i see if a category is available, and when is available, return the ID otherwise, produce the category?

Use Wordpress [cde], [cde] and [cde] method.


See wordpress_create_category().


Output is going like:


Observe that this is not extremely powerful, but, does the task.

  $CategoryName = "books";
        $categoryID = get_cat_ID($CategoryName);
        $categoryID = wp_create_category($CategoryName);

Nice all-in-one function for doing the secret. include( "../../wordpress/wp-config.php" ); include( "../../wordpress/wp-admin/includes/taxonomy.php" ); $cat_id = wp_create_category( "TESTINGLOL" ); echo "created = {$cat_id}\n"; echo "returned = " . get_cat_ID( "TESTINGLOL" ); will have to function as the category slug though.

created = 37450 returned = 37450 takes proper care of checking when the category already is available within the database. It'll return the create_category_if_not_exist($category_name, $echo = true) { $id = wp_insert_term( $category_name, 'category'); if ( $echo ) return $id; return $id; } from the category whether it is available and can return the $id from the recently produced category whether it does not pre-exist.