【发布时间】:2015-09-07 20:02:51
【问题描述】:
我正在通过自定义 WP_Query 加载可变产品
$args = array(
'post_type' => 'product',
'posts_per_page' => 100,
'product_cat' => 'beast-balls',
'orderby' => 'date',
'order' => 'desc'
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="product-node cat-beast-balls">
<?php wc_get_template_part( 'content', 'single-product' ); ?>
</div>
<?php endwhile;
}
wp_reset_postdata();
这似乎工作正常。但是,我使用 ajax 重新加载产品,但使用不同的循环,例如这个。
$args = array(
'post_type' => 'product',
'posts_per_page' => 100,
'product_cat' => 'beast-balls',
'orderby' => 'price',
'order' => 'asc'
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="product-node cat-beast-balls">
<?php wc_get_template_part( 'content', 'single-product' ); ?>
</div>
<?php endwhile;
}
wp_reset_postdata();
但是我可以注意到在“asc”和“desc”之间的顺序是颠倒的,所以至少这是有效的。我的问题是 orderby 值似乎没有什么区别。无论产品是按日期还是按价格订购,我怎样才能使循环发生变化?
谢谢大家!
【问题讨论】:
标签: php ajax wordpress woocommerce