Merge pull request #8598 from JoshKoberstein/master

Passing array of term ids to wp_set_object_terms instead of term names.
This commit is contained in:
Claudio Sanches 2015-07-17 03:15:54 -03:00
commit 8283d71442
1 changed files with 13 additions and 0 deletions

View File

@ -901,6 +901,19 @@ class WC_Meta_Box_Product_Data {
// Update post terms
if ( taxonomy_exists( $attribute_names[ $i ] ) ) {
foreach( $values as $key => $value ) {
$term = get_term_by( 'name', trim( $value ), $attribute_names[ $i ] );
if ( $term ) {
$values[ $key ] = intval( $term->term_id );
} else {
$term = wp_insert_term( trim( $value ), $attribute_names[ $i ] );
if ( isset( $term->term_id ) ) {
$values[ $key ] = intval($term->term_id);
}
}
}
wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] );
}