Why wp_insert_post creates taxonomies?

Trying to deal with the automation of the posting. Set the engine made a file that adds the post. All is well, but needed to do a taxonomy of color. For example, did the code like this:
$custom_tax = array(
 'color' => array(
$my_post = array(
 'post_title' => $var_title,
 'post_content' => "first part<!--more-->the second",
 'post_status' => 'publish',
 'post_author' => 1,
 'post_category' => array($key),
 'tags_input' => $tags,
 'tax_input' => $custom_tax //added 

 wp_insert_post( $my_post );

But they are not added. I can not understand. the taxonomy must already be added directly from code?

Altered code.
Made instead

wp_insert_post( $my_post );

$post_id = wp_insert_post($my_post);
wp_set_object_terms($post_id, 'test', 'color');


$post_id = wp_insert_post($my_post);
wp_set_object_terms($post_id,array('green', 'red'), 'color');

Not working. But if you try
wp_set_object_terms($post_id, null, 'category' );

the list of categories the post is reset to zero. I don't understand it already.

In this taxonomy work and if you ask them when manually creating the post,then everything is OK, they can be seen.

The last reason is incorrectly announced the taxonomy?

add_color_taxonomies function() { 

 'hierarchical' => false,

 'labels' => array(

 'name' => 'color',
 'singular_name' => 'color',
 'search_items' => 'Search Color',
 'popular_items' => 'Popular Colors',
 'all_items' => 'All Colors',
 'parent_item' => null,
 'parent_item_colon' => null,
 'edit_item' => 'Edit Color', 
 'update_item' => 'Update Color',
 'add_new_item' => 'Add new Color',
 'new_item_name' => 'Color',
 'separate_items_with_commas' => ",
 'add_or_remove_items' => 'Add or delete',
 'choose_from_most_used' => 'Select',
 'menu_name' => 'Color'
 'public' => true, 
 'show_in_nav_menus' => true,
 'show_ui' => true,
 'show_tagcloud' => true,
 'update_count_callback' => '_update_post_term_count',
 'query_var' => true,
 'rewrite' => array(
 'slug' => 'color',
 'hierarchical' => false 

add_action( 'init', 'add_color_taxonomies', 0 );

Do not judge strictly, I only study
July 2nd 19 at 17:07
1 answer
July 2nd 19 at 17:09
The very taxonomy you registered?

Find more questions by tags WordPress