Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $brand_list = array();
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => -1,
- );
- $products = new WP_Query($args);
- while ($products->have_posts()) {
- $products->the_post();
- $product = wc_get_product(get_the_ID());
- $brand = $product->get_attribute('pa_proizvodac');
- if (!empty($brand) && !in_array($brand, $brand_list)) {
- $brand_list[] = $brand;
- }
- }
- var_dump($brand_list);
- wp_reset_postdata();
- foreach ($brand_list as $brand) {
- echo '<h2>' . $brand . '</h2>';
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => -1,
- 'tax_query' => array(
- array(
- 'taxonomy' => 'pa_proizvodac',
- 'field' => 'slug',
- 'terms' => $brand,
- ),
- ),
- );
- $products = new WP_Query($args);
- print_r($args);
- if ($products->have_posts()) {
- while ($products->have_posts()) {
- $products->the_post();
- echo '<br><strong>' . get_the_title() . '</strong>';
- }
- }
- wp_reset_postdata();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment