Advertisement
bongzilla

Untitled

Jul 7th, 2021
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2. $query = new WP_Query( array(
  3. 'post_type' => 'product',
  4. 'post_status' => 'publish',
  5. 'posts_per_page' => -1,
  6. 'tax_query' => array( array(
  7. 'taxonomy' => 'product_cat',
  8. 'field' => 'term_id',
  9. 'terms' => array( get_queried_object()->term_id ),
  10. ) )
  11. ) );
  12.  
  13. $terms_list = array();
  14.  
  15. while ( $query->have_posts() ) : $query->the_post();
  16. $prd = get_product(get_the_ID());
  17. $attrs = $prd->get_attributes();
  18. foreach ( $attrs as $attribute ):
  19. $attribute_names = $attribute;
  20. foreach ( $attribute_names["data"]["options"] as $param ) {
  21. array_push($terms_list, $param);
  22. }
  23. // print_r($attribute_names);
  24. // echo "<pre>"; print_r($attribute_names["data"]["options"]); echo "</pre>";
  25. endforeach;
  26. // echo "<pre>"; print_r($attrs); echo "</pre>";
  27. // echo "<pre>"; print_r($prd); echo "</pre>";
  28. endwhile;
  29.  
  30. $uniq_terms = array_unique($terms_list);
  31. // print_r($uniq_terms);
  32.  
  33. wp_reset_postdata();
  34. ?>
  35.  
  36. // добавить include => $uniq_terms
  37. <?php $term_query = get_terms(array('taxonomy' =>'pa_color', 'hide_empty' => true, 'include' => $uniq_terms)); foreach ( $term_query as $term ) { ?>
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement