【问题标题】:WooCommerce seems to only orderby date and not priceWooCommerce 似乎只按日期订购而不是按价格订购
【发布时间】: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


    【解决方案1】:

    试试这个:

    $args = array(
        'post_type' => 'product',
        'posts_per_page' => 100,
        'product_cat' => 'beast-balls',
        'orderby'   => 'meta_value_num',
        'meta_key'  => '_price',
        'order' => 'asc'
        );
    

    【讨论】:

    • 雅虎!像魅力一样工作!非常感谢(:我是新的,有点小
    • 知道如何按大多数销售额排序吗? - 尝试制作 meta_key => 'total_sales' 并且成功了(:
    • 我们如何为可变产品添加按价格排序?
    猜你喜欢
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-14
    相关资源
    最近更新 更多