• Resolved matstillo

    (@matstillo)


    Hi there, I could do with just outputting the brands in a way where I have more control over the loop other than those offered by the shortcodes. I think that the Brands are set up as a taxonomy, but I’d be really gratefull if someone could offer some help on how to display the brands via wp_query: the required arguments, then also the methods for outputting things like the title & image within that loop. At some point I also need to be able to only output Brands where an image has been added, as otherwise this breaks the layout on the site. The client will add the brands, than I need to play catch up & add the logo afterwards!

    Many thanks!

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

    (@titodevera)

    Hi matstillo.

    Brands are terms of the pwb-brand taxonomy, so you need to use get_terms instead of WP_Query.

    
    $brands = get_terms( 'pwb-brand', array( 'hide_empty' => false) );
    
    foreach( $brands as $brand ) {
      $attachment_id = get_term_meta( $brand->term_id, 'pwb_brand_image', 1 );
      $logo	= wp_get_attachment_image_src( $attachment_id, 'full' );
    
      echo 'Brand ID: '   . $brand->term_id . '<br>';
      echo 'Brand name: ' . $brand->name . '<br>';
      echo 'Brand logo: ' . $logo[0] . '<br>';
    }
    

    And this for retrieving the brands of each product inside a custom WP_Query:

    
    $the_query = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => -1 ) );
    if ( $the_query->have_posts() ) {
      while ( $the_query->have_posts() ) {
        $the_query->the_post();
    
        $brands = wp_get_object_terms( get_the_ID(), 'pwb-brand' );
        var_dump( $brands );
    			
      }
      wp_reset_postdata();
    }
    
    Thread Starter matstillo

    (@matstillo)

    Hi there,

    That’s great stuff, nice support, thanks very much. That looks like that will do everything I need. Just on a slighty different note: I’m going to be using this so I can work with a modified setup of Slick Slider. In the meantime, I’m just using the carousel shortcode, but can’t get that to randomise the brands in the carousel:

    [pwb-carousel items=”16″ items_to_show=”8″ items_to_scroll=”1″ image_size=”square_small” autoplay=”true” arrows=”false” order_by=”rand”]

    It’s still just outputting them in alphabetical order. It looks like the ‘rand’ option is set up in the plugin code, can you see why that might not be working? ‘square_small’ is just a custom image size I have set up, which is working fine.

    Many thanks again!

    Mat

    Plugin Contributor titodevera

    (@titodevera)

    Hi matstillo.

    The “Order by” option is not implemented for PWB carousels.
    I will consider include it for future releases.

    Here is more info about available shortcodes:
    How can i use the available shortcodes without Visual Composer?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_query for brands’ is closed to new replies.