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!
About this post
- Posted
- Archived
- Score
- 2 · 100% up
- Kind
- Text
- ID
- rapac
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.
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.
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.
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:
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.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.
Deleted before we saved it.
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?
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.