Hello,
I am having trouble figuring out how I would display WooCommerce products in a view loop is the products and the posts have the same categories or tags. I'd like to know how to do it with both categories or tags because we use them in various ways.
So, let's say I am writing an article, and this article is about Spanish cooking. Let's say the article is tagged with the same tags as some of the products OR uses a couple of categories that the products are also using. How can I create a view that loops through only the products that are using the same tags or categories as the posts?
I hope this makes sense.
I found the setting where I can filter by taxonomy with "the same page where this view is shown", however, I am struggling with no posts showing. Will this not work if the post category is the same name as the product category, or the tags match?
Please let me know if you have any questions.
Thanks!
Dear Michael,
In your case, I suggest you try with a nested view:
1) Parent view list terms of "categories", filter by:
Taxonomy term filter
Taxonomy is set by the page where this View is inserted
and display below child view
2) Child view list "Product" posts, filter by:
Select posts with taxonomy:
Categories set by the parent Taxonomy View
And display "Product" post information.
Luo,
I tried this, and it does not work.
Is this because post categories are not the same taxonomy as product categories?
If this is the case, how can I get certain products to be related to a post when that post has the same post category name as the product has product category?
Unless I am doing this wrong, but I followed all of your directions.
Please advise.
Luo,
Just so you know, I also just tried to create a custom taxonomy called "Related Products". I associated it to both Posts and Products. Then, I added the "Select posts with taxonomy: Related Products set by the parent Taxonomy View" to the child view, and "Taxonomy is set by the page where this View is inserted" in the parent view.
No products display on the post where I put the parent view.
-----------
EDIT: this worked ... I had to make sure the new custom taxonomy was selected in the "Content Selection" of the parent view.
So, I am unable to use the default categories to connect posts and products ... I had to create a custom taxonomy that can be associated to both post types.
Thanks!!
Yes, you are right, the solution I provided above only works for "a custom taxonomy that can be associated to both post types":
https://toolset.com/forums/topic/how-can-i-display-woocommerce-products-on-posts-that-share-categories-or-tags/#post-579277
If you need "two taxonomies associated to two different post types", you can also pass the term name value as view's shortcode attribute, for example:
1) Parent view list terms of taxonomy "Post categories", filter by:
Taxonomy term filter
Taxonomy is set by the page where this View is inserted
and display below child view, and pass term name as shortcode attribute "wpvcategory" to below child view
2) Child view list "Product" posts, filter by:
Select posts with taxonomy:
Product Categories name in one of those set by the View shortcode attribute wpvcategory
eg. [wpv-view name="view-name" wpvcategory="xxxx"]
see our document:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
section "Controlling the filter with shortcode attributes"
and
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/
Value set by View shortcode attribute