복붙노트

[WORDPRESS] 한 페이지에 두 개의 우기 제품 루프를 표시하는 데 어려움이 있습니다

WORDPRESS

한 페이지에 두 개의 우기 제품 루프를 표시하는 데 어려움이 있습니다

해결법


  1. 1.$ featured_product_id를 배열로 정의했지만 다른 루프에서 건너 뛸 수있는 PastId가 추가되지 않았으며 코드 아래에서는 작동합니다.

    $ featured_product_id를 배열로 정의했지만 다른 루프에서 건너 뛸 수있는 PastId가 추가되지 않았으며 코드 아래에서는 작동합니다.

    <?php woocommerce_product_loop_start(); ?>
            <?php
            //CUSTOM LOOP
            // Display featured Products first.
    $query = new WP_Query( array(
        'post_type' => 'product',
        'post_status' => 'publish',
        'posts_per_page' => -1 ,
        'tax_query' => array( array(
            'taxonomy' => 'product_visibility',
            'field'    => 'term_id',
            'terms'    => 'featured',
            'operator' => 'IN',
        ) )
    ) );
    
    $featured_product_names = array();
    $featured_product_id = array();
    
    if ( $query->have_posts() ): while ( $query->have_posts() ): $query->the_post();
            $featured_product_id[] = get_the_ID();
            $product = wc_get_product( $query->post->ID );
            wc_get_template_part( 'content', 'product' );
    endwhile; wp_reset_query();endif;
    // fetch other product which is not featured
    $my_query = new WP_Query(array(
        'post__not_in' => $featured_product_id,
        'post_type' => 'product'
    ));
    
    if ( $my_query->have_posts() ): while ( $my_query->have_posts() ): $my_query->the_post();
    $product = wc_get_product( $query->post->ID );
    wc_get_template_part( 'content', 'product' );
    endwhile; wp_reset_query();endif;
            ?>
            <?php woocommerce_product_loop_end(); ?>
    
  2. from https://stackoverflow.com/questions/58477455/trouble-displaying-two-woo-product-loops-on-one-page by cc-by-sa and MIT license