List WooCommerce Products by Tags

Remi | July 5, 2013 | in Free

Here is a quick way to list WooCommerce products by tags using a simple shortcode. To use it, simply place the following shortcode within your pages:

[woo_products_by_tags tags=”shoes,socks”].

I created a simple plugin to do the job. Simply copy and paste the code below in new file called “woocommerce-products-by-tags.php” within a “wp-content/plugins/woocommerce-products-by-tags” folder.


The author

About the author Remi: Hey! My name is Rémi Corson, I'm a French WordPress Developer, I code stuff and I write from time to time ;-)


  1. Peter Sejersen

    Great addition to WooCommerce!

    Would it be possible to make something similar with product attributes? That would be really cool for creating great landing pages.

  2. demlaip

    Nice Code !
    Only Problem is: it only fetch the product images based on tags.

    will you please help us out in getting the shortcode for displaying product loop based on Tags at anywhere on webpage.
    the product loop I’m talking about is available right now at :

    It would be really helpful to get your response at earliest.


  3. Maria

    I seem to have issues, I’ve copied & pasted the code into the woocommerce-products-by-tags.php and then called the shortcode in one of my pages but it doesn’t read, it just reads the shortcode, that’s all. please help?

          1. rwlee33

            Hey Max, thanks for this. I don’t know exactly where to paste/replace this in the original code. Can you provide a reference line?

            I have tried it several places, but it seems to be on the same line as the thumbnail and the formatting is funny. Ideally, I’d replace the product title with this code and make a new line for the thumbnail. Thanks for the help!

  4. Jan

    Thanks Remi, but I got following error when trying to add a tag on a product:

    Warning: Cannot modify header information – headers already sent by (output started at /home/www/xxxxx/wp-content/plugins/woocommerce-products-by-tags/woocommerce-products-by-tags.php:1) in /home/www/xxxx/wp-content/plugins/woocommerce/classes/class-wc-session-handler.php on line 63,

  5. Max

    Thanks for this code, very cool. It seems similar to what I need to do in my project, but in this case I need to list products by custom field values for a given key. Do you know what I need for that process?

          1. Remi Post author

            The code is full man, just copy and paste into a file that you place in a custom folder in wp-content/plugins, and boom the magic appears!

          2. Bartek

            @Remi: Your code is 100% – I use it and like it! My previous comment was connected to @Max case:

            ” It seems similar to what I need to do in my project, but in this case I need to list products by custom field values for a given key.”

            Is it possible to change tags for custom_fields which are used to products?

            Max said that:
            “Thanks Remi, yes simply adding to args worked great:
            “meta_key” => “mymetakey”,
            “meta_value” => ” “”

            But I’m not a programmer and have a bit problem with it.

  6. timebinder

    Great plugin to display highly related items through my site, but isn’t it supposed to also link to the respective product, rather than just display the products image?


  7. leodesigner

    Hi Remi,
    I just purchased your plugin and it has been a life/time saver. I was just wondering if its possible for the results to include a link to the product as opposed to just its name and an image? Or is it supposed to be doing that already and I’m just doing something wrong. Any help would be appreciated. Thanks.

    – Leo

  8. profnimrod

    Here is a suggested change that makes all the product images clickable:

    function woo_products_by_tags_shortcode( $atts, $content = null ) {
    // Get attribuets
    "tags" => ''
    ), $atts));

    // Define Query Arguments
    $args = array(
    'post_type' => 'product',
    'posts_per_page' => 100,
    'product_tag' => $tags
    // Create the new query
    $products = new WP_Query( $args );

    $woocommerce_loop['columns'] = $columns;

    if ( $products->have_posts() ) : ?>

    have_posts() ) :
    $products->the_post(); ?>

    <?php endif;


    return '' . ob_get_clean() . '';

    add_shortcode("woo_products_by_tags", "woo_products_by_tags_shortcode");

  9. rnbronstein

    This didn’t work for me — any help? Do I need to use it in addition to your code? I’m trying to create another way of accessing the list of products — basically making it easier to parse. So having it clickable is key.

    Also, I can’t figure out how exactly to put in my own placeholder thumbnail. I specified $uploads, the file path, and the dimensions, but that didn’t work: echo ''; (I’m probably messing up something with all those commas…)
    Thanks in advance.

  10. cinders

    Excellent plugin, the original code works though it will not allow the products to be selected or listing in column fashion only vertically down the page.

    So I tried the code that allows the products to be selected and got this outcome:

    If anyone can offer a fix I would appreciate it as we would really like to get the products listed by tag and be able to be sorted by slug and choose how many columns they are listed by.

    Thank you in advance.


  11. Panchoo18

    i was using it with no problem, and suddently show me this:

    Fatal error: Call to a member function plugin_url() on a non-object in /home/ivi0/ on line 59

    what´s the problem? thx

    1. mcymer

      I had the same error, because the $woocommerce global variable wasn’t accessible. Adding the following at the top of the woo_products_by_tag_shortcode function helped:

      global $woocommerce;


  12. xonek

    Hi Remi !

    Amazing snippet and plugin and BIG THANKS for sharing it with us.
    I’m trying to use it in my website to display products on pages, but I have some issues. Is it possible to display the output in columns (by columns I mean the default woocommerce columns)? By using your code above I can display the products only in 1 column.

    Would be much appreciated if someone could help!


  13. Alaa

    Hi Sir,
    I hope everything is good with you,
    Thanks for your nice plugin,
    Do you know how can i make the following :
    Please, I need you help,
    The product category is: the product type (e.g Accessories)

    The product tag is: the city (e.g USA).

    I added these to the post if I check it.

    Now I need a modified code to filter the query by city and product type, How can i do that?.

    Best regards

  14. rogerg


    I am trying to get a shortcode to display the products by tag. (In this case we are using the tag feature for the products brand names). I believe I have followed your instructions but the actual shortcode shows on the frontend and not the relevant products which we tagged. What have I done wrong?

  15. jtibbles

    Thanks for the tutorial. I ran in to issues regarding $woocommerce->plugin_url() …it didn’t know what $woocommerce was.

    Also how could I go about adding a previous and next page link to the bottom?

    Many thanks

    1. jtibbles

      nandangse I managed to do it using some information provided at

      Here is my solution – it’s a bit dirty because I’m using a none-restful / url friendly approach…

      1) Add this before query arguments:
      $paged = ( $_GET[‘page’] ) ? $_GET[‘page’] : 1;
      2) Add this to the query arguments:
      ‘paged’ => $paged,
      3) Here’s the dirty bit…under the endwhile put the following:

      1) echo ‘Prev‘; ?>

      <?php if($pagedmax_num_pages) echo ‘Next‘; ?>

      …you can clean up part 3 if you’re following a more standard approach ie http://www.yourdomain/somepath/page/1/ , where you can utilise the get_next_posts_link( ‘Prev’, $the_query->max_num_pages ) and get_previous_posts_link( ‘Next’ ) method mentioned on that link.

  16. popocat85

    Hi, nice plugin :)
    you can create a list of only tags? For example in a shop of clothes there will be tags with link:

    like to index… Tanks and sorry for my bad English.

    1. popocat85

      Hi, sorry for my English, I asked the wrong thing, because I have not read very well.

      The plugin is great!
      But I not have link to title product and image product, I try use: echo ''.get_the_title($product_id).''; but I do not know where paste it.

      The same problem I have (where and how to paste) whit code by "profnimrod" on April 6, 2014 at 9:22 pm .

      Maybe because I use wordpress 4.2.2.?

      Please, I need you help.
      Many thanks

  17. stefoosh

    Hi Remi,
    This code was a godsend. Thank you so much!!
    My question now is how can I get the images sized properly? Currently all the images are showing up in different sizes and while they are aligned left, each single image is taking up the entire row. I’ve tried changing theshop_catalogue values around to try and get thumbnails but nothing is working. I would love to have them in grid style if possible, but will settle for just being able to size them all consistently! here’s the link so you can see what i’m talking about:

    Thanks in advance!!

  18. Trynex

    Hi, thx for code. I have one question.. Lets say I have 2 products. 1st has tags “London” and “trip”. The second has only the “London” tag. And they are both displayed even though i set up the list for tags London and Trip. But I need to display only when it has both of the tags.

    Thx for responce.

  19. fusiontribal

    I’ve tried the plugin from WP v.4.5.3 and I have this error:

    Fatal error: Call to undefined method WooCommerce::get_image_size() in /home/content/f/u/s/xxxxxxx/html/hosting/xxxxxxx/wp-content/plugins/woocommerce-products-by-tags/woocommerce-products-by-tags.php on line 57

    The line 57 refers to:
    echo get_the_post_thumbnail($loop->post->ID, ‘shop_catalog’);

    Anyone has idea about how to resolve this issue?

    By the way, Remi Corson should develop this plugin and sell it at codecanyon. Just think about.

Leave a reply