Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor titodevera

    (@titodevera)

    Hi sotos.

    Yes, you can do it. The code below retrieves all product names for the ‘Brand5’ brand:

    
    $query_args = array(
    	'post_type'      => 'product',
    	'posts_per_page' => -1,
    	'tax_query'      => array(
    		array(
    			'taxonomy' => 'pwb-brand', //brands are terms of 'pwb-brand' taxonomy
    			'field'    => 'name', //search by term name
    			'terms'    => array( 'Brand5' ) //brand names here
    		)
    	)
    );
    $the_query = new WP_Query( $query_args );
    
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '<p>'.get_the_title().'</p>';
    	}
    	wp_reset_postdata();
    }
    

    Here is more info: WP_Query

    ??

    Thread Starter sroskylos

    (@sroskylo1)

    Thank you so much @titodevera

    Happy New Year!

    Thread Starter sroskylos

    (@sroskylo1)

    How i will print the default name of the brand on terms array?
    Thanks

    Thread Starter sroskylos

    (@sroskylo1)

    Any help??? I am stack only to print the name of the brand…

    Thread Starter sroskylos

    (@sroskylo1)

    I have the code

     <?php
        // get products
        $args = array(
      'post_type'      => 'product',
      'posts_per_page' => -1,
      'tax_query'      => array(
        array(
          'taxonomy' => 'pwb-brand', //brands are terms of 'pwb-brand' taxonomy
          'field'    => 'name', //search by term name
          'terms'    => array ('WHAT TO PUT HERE?' ) //brand names here
        )
      )
    );
        $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 __( 'not found anyhting.' );
        }
        wp_reset_postdata();
      ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show all brand products with WP_Query’ is closed to new replies.