Nic*_*ick 6 wordpress woocommerce
我在 template.php 文件中使用查询来按wooCommerce类别显示产品。
我的查询如下所示:
<?php
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 99,
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'system_components',
'menu_order' => 'asc'
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'add-ons',
'menu_order' => 'asc'
)
),
'meta_query' => array(
array(
'key' => '_visibility',
'value' => 'hidden',
'compare' => '!='
)
));
$loop = new WP_Query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()) :
$loop->the_post(); ?>
.....
Run Code Online (Sandbox Code Playgroud)
这有效,我可以看到我想要的产品,而我不想要的产品则不可见。
我唯一不明白的是这'menu_order' => 'ASC'似乎不起作用。
无论我在产品设置中输入什么菜单顺序,顺序都不会改变。
我在这里做错了什么?
谢谢
从 main 中删除'menu_order' => 'asc'部分tax_query并添加到 main 中,这应该可以工作:
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 99,
'orderby' => 'menu_order',
'order' => 'ACS',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'system_components'
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'add-ons'
)
),
'meta_query' => array(
array(
'key' => '_visibility',
'value' => 'hidden',
'compare' => '!='
)
));
Run Code Online (Sandbox Code Playgroud)
正如您在文档中看到的,tax_query没有参数menu_order。
| 归档时间: |
|
| 查看次数: |
4356 次 |
| 最近记录: |