如何在woocommerce主页上查询基于类别的产品

时间:2017-11-15 05:53:15

标签: woocommerce

我正在学习woocommerce的发展。我正在尝试查询主页上的特定类别产品。但我不能像产品页面一样查询特定类别的产品。任何人都可以告诉我查询特定类别产品的正确方法。

1 个答案:

答案 0 :(得分:0)

你可以这样做:

$args = array(
        'posts_per_page' => '10',
         // change category
        'product_cat' => 'some-category',
        'post_type' => 'product',
        'orderby' => 'title',
    );


$query = new WP_Query( $args );
if( $query->have_posts()) { 
    while( $query->have_posts() ) {
        $query->the_post();
        get_the_title();
    }
}
相关问题