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.

is_category()

See wordpress_create_category().

get_cat_ID()

Output is going like:

wp_create_category()

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

<?php
  $CategoryName = "books";
  if(is_category($CategoryName))
        $categoryID = get_cat_ID($CategoryName);
  else
        $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.