Advertisement
developerjustin

Untitled

May 29th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1.  
  2. function ArrangeCategories(){
  3.  
  4.     $wooCats = get_terms( 'product_cat', 'orderby=name&order=ASC&hide_empty=0' );    
  5.     //$attCats = get_terms( 'pa_category-name', 'orderby=name&order=ASC&hide_empty=0' );     
  6.     //$attSubCats = get_terms( 'pa_sub-category-name', 'orderby=name&order=ASC&hide_empty=0' );  
  7.  
  8.     $args = array(
  9.         'post_type' => 'product',
  10.         'posts_per_page' => '-1',
  11.         'orderby' => 'title',
  12.         'order' => 'DESC'
  13.     );             
  14.    
  15.     // The Query
  16.     $the_query = new WP_Query( $args );
  17.    
  18.     // The Loop
  19.     if ( $the_query->have_posts() ) {
  20.         while ( $the_query->have_posts() ) {
  21.         $the_query->the_post();
  22.                                
  23.             $id = get_the_ID();                            
  24.                                
  25.             //$prodSubCats = wp_get_post_terms($id, "pa_sub-category-name",array("fields" => "all"));
  26.             $prodCats = wp_get_post_terms($id, array("pa_category-name","pa_sub-category-name"),array("fields" => "all"));
  27.            
  28.             foreach($wooCats as $wooCat){
  29.                 foreach($prodCats as $prodCat){
  30.                     if($prodCat->name == $wooCat->name){                       
  31.                         $term_taxonomy_ids = wp_set_object_terms( $id, $wooCat->name, 'product_cat',true);
  32.                         debug_object($term_taxonomy_ids);                  
  33.                     }
  34.                 }
  35.             }
  36.            
  37.            
  38.            
  39.            
  40.            
  41.                            
  42.         }
  43.     } else {
  44.         // no posts found
  45.     }  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement