我正在学习woocommerce开发。我正在尝试在主页上查询特定类别的产品。但是我无法像产品页面一样查询特定类别的产品。任何人都可以向我展示查询特定类别产品的正确方法。
你可以
这样做:
$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();
}
}