Support » Plugin: YITH WooCommerce Multi Vendor » Show vendor products in a loop

  • I’m trying to create a custom template page and I wan to show a products of a single vendor in a list.

    I’m trying with this loop, but this show all products and didn’t get the vendor ID i pass in a variable

    <?php
    
        $id_vendor = get_field('id_venditore');
    
            $args = array(
                'post_type' => 'product',
            'tax_query' =>
              array(
                'taxonomy' => 'yith_shop_vendor',
                'field' => 'id',
                'terms' => '$id_vendor',
                ),
                );
            $loop = new WP_Query( $args );
            if ( $loop->have_posts() ) {
                while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
              <?php the_title(); ?>
    
              <?php echo $id_vendor; ?>
    
          <?php  endwhile;
            } else {
                echo __( 'No products found' );
            }
            wp_reset_postdata();
        ?>
    • This topic was modified 1 year, 2 months ago by elias90.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi there,

    thanks for contact us! We need to understand which kind of page is this because we need to find the correct way to retrieve the vendor_id.

    Is this a vendor taxonomy page ?

    Let us know.
    Have a nice day

    YITH

    @elias90

    $vendor = yith_get_vendor( ‘current’, ‘user’ );

    $args = array(
    			'post_type' => 'product',
    			'posts_per_page' => -1,
                'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit'),
                'tax_query' => array('relation' => 'AND',
    
                    array(
                        'taxonomy' => 'yith_shop_vendor',
                        'field' => 'term_id',
                        'terms' => $vendor->term_id,
                        'operator' => 'IN'
                    )
                )
    			);
    		$loop = new WP_Query( $args );
    
    		if ( $loop->have_posts() ) {
    			while ( $loop->have_posts() ) : $loop->the_post();
                    echo get_the_title();
    			endwhile;
    		}
    
            wp_reset_postdata();
    Plugin Author YITHEMES

    (@yithemes)

    Hi there,

    $vendor = yith_get_vendor( ‘current’, ‘user’ ); Works means the current logged in user is a vendor

    If this is what you want the code is correct.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show vendor products in a loop’ is closed to new replies.