Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ArrangeCategories(){
- $wooCats = get_terms( 'product_cat', 'orderby=name&order=ASC&hide_empty=0' );
- //$attCats = get_terms( 'pa_category-name', 'orderby=name&order=ASC&hide_empty=0' );
- //$attSubCats = get_terms( 'pa_sub-category-name', 'orderby=name&order=ASC&hide_empty=0' );
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => '-1',
- 'orderby' => 'title',
- 'order' => 'DESC'
- );
- // The Query
- $the_query = new WP_Query( $args );
- // The Loop
- if ( $the_query->have_posts() ) {
- while ( $the_query->have_posts() ) {
- $the_query->the_post();
- $id = get_the_ID();
- //$prodSubCats = wp_get_post_terms($id, "pa_sub-category-name",array("fields" => "all"));
- $prodCats = wp_get_post_terms($id, array("pa_category-name","pa_sub-category-name"),array("fields" => "all"));
- foreach($wooCats as $wooCat){
- foreach($prodCats as $prodCat){
- if($prodCat->name == $wooCat->name){
- $term_taxonomy_ids = wp_set_object_terms( $id, $wooCat->name, 'product_cat',true);
- debug_object($term_taxonomy_ids);
- }
- }
- }
- }
- } else {
- // no posts found
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement