Reputation: 8809
I am trying to add terms using code but it's not added into wordpress. I am using below code to add
$term = wp_insert_term('Jogger', 'product_style',0);
Every time it return Invalid taxonomy
. I have check my db and I don't found any entry for this. Even I have check with term_exists('Jogger', 'pa_style',0);
and it also return 0. Can some have any idea about it.
I am able to add other terms like
$term = wp_insert_term('SPORTS', 'product_cat',0);
Upvotes: 1
Views: 5973
Reputation: 303
Use this code in functions.php
add_action( 'init', 'create_new_taxonomy' );
function create_new_taxonomy() {
register_taxonomy(
'product_style',
'products',
array(
'label' => __( 'Product Style' ),
'rewrite' => array( 'slug' => 'product_style' ),
'hierarchical' => true,
)
);
}
You can't insert term here because your taxonomy is not registered. So use the above code register it first. Then insert term.
Upvotes: 1