Skip to content

Can't get Woocommerce product tag filtering to work, pulling hair out.

I've built a recent item slider for the front page of my site, but now I'm trying to add a similar slider to a blog page that only gets the products from certain product tags.

Here is the code I have now that isn't working. It displays all products, no matter the product tag.

$args = array( 'post_type' => 'product', 'posts_per_page' => 12,'product_tag' => '16' );

I've also tried; 'cat' => '16' 'product_cat' => 'shoes' 'product_cat' => '16' 'product_tag' => 'shoes' 'slug' => 'shoes'

Does anybody have any suggestions? I'm completely stuck on this issue!

2 points10 comments
Open on Reddit
About this post
Posted
Archived
Score
2 · 100% up
Kind
Text
ID
rapac

Author

22
posts
82
comments
15
media
View profile

11 comments

I can't fully help you. But I suggest posting this in the WooCommerce support board, the team usually get to it fairly quickly and will be able to help you out on any issue.

1 points

I didn't think I could access the forums unless I had a monthly subscription. After clicking around for a few minutes I posted on the forums. Thanks for the reminder/notice.

I've been going crazy with this plugin.

1 points

No problem, I have a subscription so if they don't let you post it. I can post it for you. I hope you find your answer.

1 points

I'll start by saying I don't have any experience with WooCommerce specifically.

a quick glance at source shows 'product_cat' and 'product_tag' are two separate taxonomies, I'm sure you're aware of this. If it's indeed a 'product_tag', the 'product_cat' stuff won't work, so let's eliminate all that.

A simple taxonomy query requires the term slug, so 'product_tag' => '16' won't work.

Moving forward, 'tax_query' will be the preferred method for taxonomy queries, so try something like this:

$args = array(
    'post_type' => 'product',
    'posts_per_page' => 12,
    'tax_query' => array(
        array(
            'taxonomy' => 'product_tag',
            'field' => 'id',
            'terms' => 16
        )
    )
);

$query = new WP_Query( $args );

if this doesn't get you the results you're after, add print_r( $query ); immediately after the query and look at the parameters and actual SQL being constructed for this query to determine if there's some other code/plugin interfering.

1 points

I finally got it working with 'product_tag' => shoes...but for some reason, it outputs three of each product with the tag "shoes".

It is weird and I'm not sure exactly why it is doing it. The html output only shows that one product is displaying, but the jquery slider is showing the product three times.

1 points
unknown author

Deleted before we saved it.

1 points

Thanks, I got it sorted out and the other problems that came with it.

Any thoughts on why this won't echo a thumbnail and just displays the placeholder.png?

?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');

else echo '<img src="'.$woocommerce->plugin_url().'/assets/images/placeholder.png" alt="Placeholder" />'; ?>

I attached a category thumbnail when creating it, but under Media, it doesn't show that it is attached to anything.

Any help is very much appreciated. I'm a little over my head with this project, I don't have a ton of experience in programming but can usually get WP to do what I need it to do.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.