Advertisement
Guest User

Untitled

a guest
Jan 15th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1.  
  2.         //link the product to the category
  3.         $cats = explode ( '|', $data[3] );
  4.         foreach ($cats as $cat){
  5.             $cat_taxs = explode( '->', $cat );
  6.             $parent = false;
  7.             foreach ( $cat_taxs as $cat_tax)
  8.             {
  9.                 $new_cat = term_exists( $cat_tax, 'product_cat' );
  10.                 if ( ! is_array( $new_cat ) ) {
  11.                     $new_cat = wp_insert_term(  $cat_tax, 'product_cat', array( 'slug' => $cat_tax, 'parent'=> $parent) );
  12.                 }
  13.                 $x = wp_set_object_terms( $post_id, (int)$new_cat['term_id'], 'product_cat', true );
  14.                 $parent = $new_cat['term_id'];
  15.                
  16.                 //check out http://wordpress.stackexchange.com/questions/24498/wp-insert-term-parent-child-problem
  17.                 delete_option("product_cat_children");
  18.             }
  19.             unset($parent);
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement