0 レビュー
1 回答
php-フロントページに2つのwoocommerceカテゴリを表示します
モバイルとラップトップという2つのカテゴリがあり、メインページに両方を同時に表示したいと思います。このコードを使用しましたが、カテゴリの1つしか表示されていません。ご協力ありがとうございました
<?php $products= new WP_Query(
array(
'post_type'=>'product',
'posts_per_page'=>'-1',
'product_cat' => 'mobile+laptop',
'orderby' => 'rand',
)
); ?>
わからない
0
レビュー
答え :
解決:
tax_query
使用できます。以下のコードを試してください。
<?php $products = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => -1, 'orderby' => 'rand', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'mobile' ), array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'laptop' ) ), ) ); ?>
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。