WooCommerce list products by attribute with multiple values

By default WooCommerce allows you to list products by attribute using this shortcode: [product_attribute attribute=’color’ filter=’black’], but this shortcode accepts only one single value for your attribute. That means that this shortcode [product_attribute attribute=’color’ filter=’black,red,white’] will not return anything.

That’s why i coded this small plugin that will allow you to set as many values for your attribute as you want. To use, simply place this shortcode:

[woo_products_by_attributes attribute=”colour” values=”red,black” per_page=”5″]

Remember, you can define only one attributes, but this attribute can have as many values as you want!

31 responses to “WooCommerce list products by attribute with multiple values”

  1. Peter Sejersen

    Really nice work. I can definitely see this work – eg. for making awesome landing pages with specific products.

    Another question regarding attributes: Is it possible in some way to turn the product attributes in the Additional information tab into links? I would like to be able to click on the an attribute value on the product page and then come to an archive page of some sort, where I can see all products with this attribute.

    I know this is maybe a bit off topic, but you can maybe use it as an idea for a future post :-) I think it is something all WooCommerce shop users could benefit from.

  2. Nimitz

    how about the catgories, for example, if the product is under the category that has this kind of attributes?

  3. Johann

    good work,
    we search for a Product Tag Cloud, which loads Product Tags dynamically -depending what Attribute/Product Category or Taxonomy is choosen by users..

    example: clicking on Product Category XY -> all Product Tags from the Products in the Category are loaded in a widget..
    (same as woo layered navigation, but with product-tags&Cloud)

    If you want to do such a (paid) Cloud please contact me, thanks johann

    1. Thanks, but i’m sorry i don’t do custom jobs! ;-)

  4. Yonathan

    Hi Remi,

    Can I display products without a custom attribute, so example:

    [woo_products_by_attributes attribute=”colour” values=”” per_page=”5″]

    so that the page will display products without colour attributes?

    Thanks in advance :)

  5. jamesdean

    Hi Remi,

    Nice plugin, thankyou.

    We would like to filter using two attributes instead of one, for example:
    – Colour: red, green
    – Size: S,M,L.

    So display for example all of the products that are red and size S.

    Any idea of how could we do that?

    Thanks in advance.

  6. mikehaceman

    I know it is probably stupid question. But how you implement this code? I am not a coder but would like to use this piece of work. Do you have some steps by steps guide?


    1. Jhonnu

      Hi mikehaceman,
      Any code that starts with * Plugin Name:
      * Plugin URI:
      * Description:
      * Version:
      * Author:
      * Author URI:
      * Requires at least:
      * Tested up to:
      * Text Domain: –
      * Domain Path:

      ect is a plugin like those found in the wordpress repository however you have to turn it into a file yourself. You’d copy the entire code and paste to a text editor ( I’ve used texteditor on Mac). Go up to the file menu to choose formatting and make this plain text. Save with thexetention . php. Then zip to upload in th eupload plugins tab of your wp admin.

  7. werm42

    any plans to update this so it only finds in-stock products in it’s array?

    If not, any thoughts on how to accomplish this?

  8. Jhonnu

    So does this paginate?

  9. Jhonnu

    Is there a shortcode to show just the attribute value of a product like
    [brand] ?

  10. dirtyfeeling

    Hey Remi, will this work to show a product list filtered in a page, and make this work with the attribute filter of the sidebard? (like the default shop or a category page)

  11. manyakama

    Hi Remi,

    Here is my shortcode:

    [woo_products_by_attributes attribute=”szintek” values=”1. szint – Kezdő” per_page=”50″ columns=”3″ orderby=”title” order=”desc”]

    but it isn’t work. Is it correct?
    Or maybe it can work just in the shop pages? and in any other pages not?

    1. i guess it’s due to special characters “1. szint – Kezdő”

  12. elise

    Dear Sir,
    Does this plugin support multiple attributes filtering?

    For an instance, initial example is:
    [woo_products_by_attributes attribute=”colour” values=”red,black” per_page=”5″]
    where only one attribute is involved in filtering.

    And the thing I’m looking for possibly would look somehow like:

    [woo_products_by_attributes attribute=”colour” values=”red” && attribute= “size” value=”large” per_page=”5″]

    where the filtering is taking place by two attributes simultaneously.

    If it doesn’t, then could you please help me out with this. I would highly appreciate it.

  13. jamesdean

    Hi Remi,

    How could we display 5 columns instead of 4?

    I’ve managed to change the number of columns in the shortcode “[product_category category ” by adding the css code:

    .woocommerce.columns-5 .products .product {
    position: relative;
    width: 16.5%;

    I’ve tried to change the number of columns in your plugin but instead of 5 it displays 3 and 2. Maybe I should change the css somewhere but I don’t know exactly where.

    Could you please give me a tip?

    Kind regards.

  14. dademaru

    Hi Remi,

    is this shortcode working with WC 2.2.x?
    I’ve tried using different values but I get only one product.
    Maybe it displays only the product that has all this values?
    The logic should be OR, not AND, so if colors are blue, green, red, display the products that have green attribute, the products with blue attribute, …
    not only the product that has all these attribute.
    Could this be the reason why I have only one product displayed?

    1. dademaru

      It was all my fault :-(
      I used the wrong attribute.
      Ignore my previous comment.


    2. sunnydadi

      Hi Dademaru,

      Is it worked for you?
      I am trying to achieve this, but didn’t work out..

  15. xtobix

    Hi Remi, where do I include the plugin code above? Do I need to create a new folder in the plugins folder? Sorry for the question but I never worked with custom plugins before. Thanks in advance!

    1. Hey, you create a folder in wp-content/plugins, name it whatever you want, and create a new file in this folder. Place the code in that file and you’re good to go!

      1. xtobix

        Thank you, works great!

  16. genest

    But it’s not working if the tag include a space
    Example “Assiettes plates”
    Is there a solution?

  17. vinay

    Hi Remi,

    Thanks for posting such a wonderful article, it has really solved my problem, i am using your code and i’ve made few more changes in it for some other attributes as well. I am using it very well, but i got stuck with something, i am passing values to this plugin in php on run time via AJAX and its working fine however the only problem is that when i am passing values during run time via ajax call, the pagination doesn’t works.

    What i am doing is that, i have two different product one is main and nother is an addon on that so in single product page I am listing various addon products along with there prices but since that list is long i am not able to paginate them. so that i can move forward with other addon product and check which fits with the current product.

    So how can i do the pagination when i pass values during runtime.


  18. sergsce


    Why $products->have_posts() not return anything. Shortcode product_attribute works normal.
    Wordpress 4.8.1

  19. kalyani@324

    I am go through your plugin link


    attribute-with-multiple-values/ but dont know how to use it in my

    wordpress site….Please help me in that

Leave a Reply