我已经在我的自定义模板上进行了自定义查询,我想按价格范围按特定类别显示产品,就像我有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>
最合适的回答,由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();