Title: WP_Error on attribute + term insert
Last modified: September 27, 2018

---

# WP_Error on attribute + term insert

 *  Resolved [SpabRice](https://wordpress.org/support/users/spabrice/)
 * (@spabrice)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/wp_error-on-attribute-term-insert/)
 * Hello,
 * I want to add a product attribute (wc_create_attribute) & assigned terms (wp_insert_term)
   via the functions.php.
 * Example:
 *     ```
       $args      = array(
       			'name'         => "Color",
       			'slug'         => "color",
       			'order_by'     => "menu_order",
       			'has_archives' => "",
       		);
       		wc_create_attribute($args);
   
       		$add = wp_insert_term( "Blue", 'pa_color', array( 'slug' => "blue" ) );
       		print_r($add);
       ```
   
 * The wc_create_attribute works fine, but when the wp_insert_term runs it throws
   an error because of “Invalid taxonomy”.
    When I then reload the page, it works
   fine because then the taxonomy is not invalid anymore. So it seems that the wp_insert_term
   are executed before the create_attribute somehow. I don’t understand why it does
   not work in one attempt.
 * Maybe you can help me

Viewing 1 replies (of 1 total)

 *  Plugin Support [slash1andy](https://wordpress.org/support/users/slash1andy/)
 * (@slash1andy)
 * Automattic Happiness Engineer
 * [7 years, 5 months ago](https://wordpress.org/support/topic/wp_error-on-attribute-term-insert/#post-10816240)
 * Hey there!
 * I’d recommend asking in the Advanced WooCommerce Group on Facebook([https://www.facebook.com/groups/advanced.woocommerce](https://www.facebook.com/groups/advanced.woocommerce))
   to see if someone can help you out there.
 * Hopefully that helps! Have a great one!

Viewing 1 replies (of 1 total)

The topic ‘WP_Error on attribute + term insert’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [slash1andy](https://wordpress.org/support/users/slash1andy/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/wp_error-on-attribute-term-insert/#post-10816240)
 * Status: resolved