中继器领域的产品类别

问题描述 投票:0回答:1

我试图在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>
php woocommerce repeater advanced-custom-fields
1个回答
0
投票

这对我有用:

<?php if( have_rows('product_categories') ): ?>

<ul class="products">

    <?php while( have_rows('product_categories') ): the_row(); ?>

        <?php
        $product_cats = get_sub_field('product_category');
        $args = array(
            'post_type'             => 'product',
            'post_status'           => 'publish',
            'posts_per_page'        => '12',
            'tax_query'             => array(
                array(
                    'taxonomy'      => 'product_cat',
                    'field' => 'term_id',
                    'terms'         => $product_cats,
                    'operator'      => 'IN',
                    'field'         => 'slug'
                ),
            )
        );
        $loop = new WP_Query($args);
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>

            <?php wc_get_template_part( 'content', 'product' ); ?>

        <?php endwhile; ?>

        <?php wp_reset_query(); ?>

    <?php endwhile; ?>

</ul>
© www.soinside.com 2019 - 2024. All rights reserved.