我有一个自定义产品类型和自定义循环用于列出 woocommerce 产品
$query_args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'custom_type',
),
),
);
$r = new WP_Query( $query_args );
if ( $r->have_posts() ) {
我在产品数据中有自定义数据属性。我如何在循环中使用它们?如何过滤具有此属性的产品?
例如,我有颜色和尺寸数据属性。现在我如何列出红色和大型产品?
属性只是自定义分类法。请记住,分类名称始终是前面带有pa_
。这只是 WooCommerce 的命名约定,以避免分类名称冲突。要查询多个分类法,请参阅《多分类法处理》部分WP 查询参数.
例如,如果您尝试查询产品类型=的产品custom_type
和颜色=red
and尺寸属性=large
,您的示例参数将如下所示:
$query_args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => 'custom_type',
),
array(
'taxonomy' => 'pa_color',
'field' => 'slug',
'terms' => 'red',
),
array(
'taxonomy' => 'pa_size',
'field' => 'slug',
'terms' => 'large',
),
),
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)