the function wp_insert_term
returns the newly created term id (or WP_Error on error), so once your create your term you need to store it’s ID and then you can save the “extra fields” using get_option
, update_option
something like:
if($_SERVER['REQUEST_METHOD'] == "POST") {
$clientName = $_POST["clientName"];
$term_id = $_POST["clientName"];
$clientKeywords = $_POST["clientKeywords"];
$clientSlug = $_POST["clientSlug"];
$parent="";
$errorType="Category "". $clientName .'" Added!';
$term_id = wp_insert_term($clientName, 'category', array(
'description'=>$clientKeywords,
'slug'=>sanitize_title($clientSlug),
'parent'=>$parent
));
if (!is_wp_error($term_id)){
//save here
$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
$tag_extra_fields[$term_id]['field'] = strip_tags($_POST['field']);
$tag_extra_fields[$term_id]['field2'] = strip_tags($_POST['field2']);
update_option(MY_CATEGORY_FIELDS, $tag_extra_fields);
}
}