• Resolved ilanb

    (@ilanb)


    Hi,

    I’m pro user… I write request here because support message not work actualy…

    I try to add custom query in store page, I use :

    <ul class="products">
                            <?php
                            $args = array(
                                'post_type' => 'product',
                                'posts_per_page' => 8,
                                'product_cat' => $product_cat_id
                            );
                            $loop = new WP_Query( $args );
                            if ( $loop->have_posts() ) {
                                while ( $loop->have_posts() ) : $loop->the_post();
                                    wc_get_template_part( 'content', 'product' );
                                endwhile;
                            } else {
                                echo __( 'No products found' );
                            }
                            wp_reset_postdata();
                            ?>
                        </ul>

    But not work, always product not found, why this simply code not work, it pretty much like this working code :

    <?php
                        woocommerce_product_loop_start();
                        // Add short description in store
                        add_action( 'woocommerce_after_shop_loop_item_title', 'tutsplus_excerpt_in_product_archives', 40 );
                        ?>
                            <?php
                            while ( have_posts() ) : the_post(); ?>
                                <?php wc_get_template_part( 'content', 'product' );  ?>
                            <?php endwhile; // end of the loop. ?>
    
                        <?php
                        woocommerce_product_loop_end();

    Any chance to make custom product loop in store.php ??

    Thanks

    • This topic was modified 6 years, 8 months ago by ilanb.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @ilanb, just use this code. Hopefully this will work for you. regards ??

    <ul class="products">
        <?php
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 8,
            'tax_query' => array(
                array(
                    'taxonomy' => 'product_cat',
                    'field'    => 'term_id',
                    'terms'    => array( $product_cat_id )
                )
            )
        );
    
        $loop = new WP_Query( $args );
    
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                wc_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
        ?>
    </ul>

    Hello @ilanb, Please use this code, hopefully it will work. Thanks

    <ul class="products">
        <?php
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 8,
            'tax_query' => array(
                array(
                    'taxonomy' => 'product_cat',
                    'field'    => 'term_id',
                    'terms'    => array( $product_cat_id )
                )
            )
        );
    
        $loop = new WP_Query( $args );
    
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                wc_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
        ?>
    </ul>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom product loop in store.php’ is closed to new replies.