Skip to main content
Grammar
Source Link
Dave Romsey
  • 17.9k
  • 11
  • 55
  • 70

Display product attributes for current product post

I'm trying to display the attributes of the current postproduct. Here inIn the screenshot below, I declared anthe attribute which is "Liquor Brands" withand assigned multiple values to it:

enter image description here

Here is the code I'm currently working on:

        <?php

        $liquor = new WP_Query( array( 
            'post_type'   => 'product',
            'product_cat' => 'liquors',
            'meta_query'  => array(
                array(
                    'key'   => '_stock_status',
                    'value' => 'instock'
                )
            )
        ) );

        if ( $liquor->have_posts() ) : while ( $liquor->have_posts() ) : $liquor->the_post();

        ?>

        <?php 

        $liquor_brands = get_terms('pa_liquor-brands');
        foreach ( $liquor_brands as $liquor_brand ) :
        ?>

        <?php endforeach; ?>



        <div id="post-<?php the_ID(); ?>"  class="three columns product-post">

        <?php echo $liquor_brand->slug ?>

        </div>



        <?php wp_reset_postdata(); ?>

        <?php endwhile; else: ?>

        <?php //error message ?>

        <?php endif; ?>


        <?php wp_reset_query(); ?>

Here is the screenshot of the output. It only shows the last value that I have set, which is "very-old-captain-rum":

enter image description here

Display product attributes for current product post

I'm trying to display the attributes of the current post. Here in the screenshot below I declared an attribute which is "Liquor Brands" with multiple values

enter image description here

Here is the code I'm currently working on

        <?php

        $liquor = new WP_Query( array( 
            'post_type'   => 'product',
            'product_cat' => 'liquors',
            'meta_query'  => array(
                array(
                    'key'   => '_stock_status',
                    'value' => 'instock'
                )
            )
        ) );

        if ( $liquor->have_posts() ) : while ( $liquor->have_posts() ) : $liquor->the_post();

        ?>

        <?php 

        $liquor_brands = get_terms('pa_liquor-brands');
        foreach ( $liquor_brands as $liquor_brand ) :
        ?>

        <?php endforeach; ?>



        <div id="post-<?php the_ID(); ?>"  class="three columns product-post">

        <?php echo $liquor_brand->slug ?>

        </div>



        <?php wp_reset_postdata(); ?>

        <?php endwhile; else: ?>

        <?php //error message ?>

        <?php endif; ?>


        <?php wp_reset_query(); ?>

Here is the screenshot of the output. It only shows the last value that I have set which is "very-old-captain-rum"

enter image description here

Display product attributes for current product

I'm trying to display the attributes of the current product. In the screenshot below, I declared the attribute "Liquor Brands" and assigned multiple values to it:

enter image description here

Here is the code I'm currently working on:

        <?php

        $liquor = new WP_Query( array( 
            'post_type'   => 'product',
            'product_cat' => 'liquors',
            'meta_query'  => array(
                array(
                    'key'   => '_stock_status',
                    'value' => 'instock'
                )
            )
        ) );

        if ( $liquor->have_posts() ) : while ( $liquor->have_posts() ) : $liquor->the_post();

        ?>

        <?php 

        $liquor_brands = get_terms('pa_liquor-brands');
        foreach ( $liquor_brands as $liquor_brand ) :
        ?>

        <?php endforeach; ?>



        <div id="post-<?php the_ID(); ?>"  class="three columns product-post">

        <?php echo $liquor_brand->slug ?>

        </div>



        <?php wp_reset_postdata(); ?>

        <?php endwhile; else: ?>

        <?php //error message ?>

        <?php endif; ?>


        <?php wp_reset_query(); ?>

Here is the screenshot of the output. It only shows the last value that I have set, which is "very-old-captain-rum":

enter image description here

Source Link
clestcruz
  • 201
  • 1
  • 6
  • 13

Display product attributes for current product post

I'm trying to display the attributes of the current post. Here in the screenshot below I declared an attribute which is "Liquor Brands" with multiple values

enter image description here

Here is the code I'm currently working on

        <?php

        $liquor = new WP_Query( array( 
            'post_type'   => 'product',
            'product_cat' => 'liquors',
            'meta_query'  => array(
                array(
                    'key'   => '_stock_status',
                    'value' => 'instock'
                )
            )
        ) );

        if ( $liquor->have_posts() ) : while ( $liquor->have_posts() ) : $liquor->the_post();

        ?>

        <?php 

        $liquor_brands = get_terms('pa_liquor-brands');
        foreach ( $liquor_brands as $liquor_brand ) :
        ?>

        <?php endforeach; ?>



        <div id="post-<?php the_ID(); ?>"  class="three columns product-post">

        <?php echo $liquor_brand->slug ?>

        </div>



        <?php wp_reset_postdata(); ?>

        <?php endwhile; else: ?>

        <?php //error message ?>

        <?php endif; ?>


        <?php wp_reset_query(); ?>

Here is the screenshot of the output. It only shows the last value that I have set which is "very-old-captain-rum"

enter image description here