• Resolved spirit1nfernal

    (@spirit1nfernal)


    Could anyone help with retrieving full list of added custom attributes from WC plugin within a loop, which gets product categories?

    Now doing following:

    <ul class="collapsible" data-collapsible="accordion">
    	<?php
      $taxonomy     = 'product_cat';
      $orderby      = 'name';
      $show_count   = 0;
      $pad_counts   = 0;
      $hierarchical = 0; 
      $title        = '';
      $empty        = 0;
    
      $args = array(
    		 'taxonomy'     => $taxonomy,
    		 'orderby'      => $orderby,
    		 'show_count'   => $show_count,
    		 'pad_counts'   => $pad_counts,
    		 'hierarchical' => $hierarchical,
    		 'title_li'     => $title,
    		 'hide_empty'   => $empty
      );
     $all_categories = get_categories( $args );
     foreach ($all_categories as $cat) {
    		$category_id = $cat->term_id;
    ?>
                <li>
    		<div class="collapsible-header">
    			<p class="openSemi black-text">
    				<?php echo $cat->name ?>
    			</p>
    			<div class="triangle-cover hide"></div>
    			<div class="triangle hide"></div>
    		</div>
    		<div class="collapsible-body">
    <?php
    $goodsArgs = array(
    	'post_type' => 'product',
    	'product_cat' => $cat->name,
    	'hide_empty'   => 0,
    	'post_per_page' => 1
    );
    	 $i=0;
    		$wc_query = new WP_Query( $goodsArgs );
    		while ($wc_query->have_posts()) :
    			$wc_query->the_post();
    			global $product;
                            $mans = get_the_terms( $product->id, 'pa_manufacturer');
    			foreach($mans as $manufacturer) {
    ?>
    		<p class="exo2Medium black-text">
    		  <input type="checkbox" id="<?php echo 'manufacturer ' . $i; ?>" />
    		  <label class="exo2Medium black-text" for="<?php echo 'manufacturer ' . $i; ?>">
    		  <?php echo $manufacturer->name; ?>
    		  </label>
    		</p>
    <?php
    			$i++;
    			};
    			endwhile;
    	 wp_reset_postdata();
    ?>
    		</div>
    	</li>
    	<?
    	} wp_reset_query();
    	?>
    	</ul>
    

    As expects all above must throw out front-end a dropdown list with categories of products (two categories with checkboxes, which contains custom attributes for each category (didn’t found better way to store manufaturers). But it show only both categories and one product manufaturer, who linked to already added product.

    What already tried to do: tried to use custom loop from native wordpress wp_query function – gives strange result, when manufacturer, who have added product lists three times for one category; tried didn’t specify conditions, then munfacturer who have added product – shows for both different categories, and products already added is added only into one of them.

    I understand, that I doing something wrong, but can’t understand, where is hidden my mistake. Please, help me find it. Thanks

  • The topic ‘get a custom attribute value within loop’ is closed to new replies.