【发布时间】:2019-07-17 16:10:03
【问题描述】:
我试图在 ACF 转发器字段中显示特定的产品类别。 这会不断输出所有产品类别。
如何为每个转发器字段输出单个类别?
<?php if( have_rows('product_categories') ): ?>
<ul class="products">
<?php while( have_rows('product_categories') ): the_row(); ?>
<?php
$product_category_ids = get_sub_field('project_category');
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'tax_query' => array(
'taxonomy' => 'product_cat',
'terms' => $product_category_ids
),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' ); ?>
<?php
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>
<?php endwhile; ?>
</ul>
【问题讨论】:
-
您应该在“tax_query”中添加“field”参数
-
谢谢,还是漏掉了几个参数....大大的叹息
标签: php woocommerce repeater advanced-custom-fields