如何按定价查询WooCommerce产品?

时间:2018-02-17 作者:Md Abul Bashar

我已经在我的自定义模板上进行了自定义查询,我想按价格范围按特定类别显示产品,就像我有10种产品一样。价格是10美元、20美元、15美元、25美元等等。现在我想展示一下从低到高的产品。示例10、15、20、25,如分拣系统。这是我的查询代码。请分享我需要添加的代码,以及显示从低到高的查询代码。

<div class="combination-page fix">
    <div class="single-combination-area fix">

        <?php 
            $com_query = array(
                \'post_type\'     => \'product\',
                \'posts_per_page\' => 10,
                \'product_cat\' => \'combinations\',                        
            );

        $comba = new WP_Query($com_query); 

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

            $com_size = get_post_meta(get_the_ID(), \'combinations-size\', true);
            $com_food_menus = get_post_meta(get_the_ID(), \'combinations-food-menus\', true);
        ?>
        <!--Single Combinations Product-->
        <div class="single-combination fix">
            <!--Single Combinations Product left-->
            <div class="single-com-image floatleft">
                <a href="<?php the_permalink(); ?>">
                <?php if(has_post_thumbnail( get_the_ID())){

                     echo get_the_post_thumbnail( get_the_ID(), \'com_product_img\' );
                } else {
                    echo \'<img src="\' . woocommerce_placeholder_img_src() . \'" alt="Placeholder" />\';
                }
                ?>



                </a>
            </div><!--/ Single Combinations Product left-->

            <!--Single Combinations Product Right-->
            <div class="single-com-product-details floatleft">
                <!--Single Combinations Header-->
                <div class="single-com-header fix">
                    <div class="single-com-name fix">
                        <h2><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( $product->get_title() ) ?>"><?php the_title(); ?></a></h2>

                        <div class="single-com-price floatright">
                            <h2><span>Price : </span><?php echo $product->get_price_html(); ?></h2>
                        </div>
                    </div>
                    <div class="single-com-info fix">
                        <?php if($com_size) : ?>
                        <div class="single-com-size">
                            <p><span> Size : </span><?php   echo $com_size; ; ?></p>
                        </div>
                        <?php endif; ?>
                    </div>
                </div><!--/ Single Combinations Header-->

                <!-- Single Combinations description-->
                <div class="single-com-description">
                    <p><?php echo $product->post->post_excerpt; ?></p>
                </div><!--/ Single Combinations description-->

                <!-- Single Combinations Footer-->
                <div class="single-com-footer">
                    <div class="single-com-foodmenu floatleft">
                        <?php if($com_food_menus) : ?>
                        <ul>                            

                            <p>Food Menus: </p>

                            <?php foreach($com_food_menus as $food_menu) {
                            echo "<li>$food_menu</li>";

                            }
                        ?>
                        </ul>
                        <?php endif; ?>
                    </div>
                    <div class="single-com-addtocart floatright">                               
                        <?php woocommerce_template_loop_add_to_cart(); ?>
                    </div>
                </div><!-- / Single Combinations Footer-->
            </div><!--/ Single Combinations Product Right-->
        </div><!--/ Single Combinations Product-->

        <?php endwhile;  endif;?>
    </div>
</div>

1 个回复
最合适的回答,由SO网友:Sureshbabu T 整理而成
$args = array(
    \'post_type\'      => \'product\',
    \'posts_per_page\' => 10,
    \'orderby\'        => \'meta_value_num\',
    \'meta_key\'       => \'_price\',
    \'order\'          => \'asc\'
);

$loop = new WP_Query( $args );
echo \'<form id="checkme">\';
while ( $loop->have_posts() ) : $loop->the_post();
    global $product;
    echo \'<div>\';
    echo \' <input type="radio" name="products" value="\'.get_the_title().\'" >\';
    echo \'<label>\' . woocommerce_get_product_thumbnail().\' \'.get_the_title().\'</label>\';
    echo \'</div>\';
    /*    echo \'<br /><a href="\'.get_permalink().\'">\' . woocommerce_get_product_thumbnail().\' \'.get_the_title().\'</a>\';*/
endwhile;
echo \'</form>\';
wp_reset_query();
结束

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post