Hi, I’m back again with the same topic - related products. I know that you can now query related products by clicking on it in the woocommerce section in query. But I need to list only those products that share the category I indicated. How do I do that?
Browser: Chrome 110 OS: macOS / Windows / Linux / etc. URL: Link to a page that illustrates this issue Video: Short screen recording that illustrates this issue (free tool: jam.dev)
[Please describe this bug in as much detail as possible so we can replicate & debug this bug]
I don’t see a bug here , so I’ve moved it to the How To topic.
By default, it will show you products that are inside the same category or tag, but if you want to have anything custom, then you can create new custom query loop, and manually select which category you want.
Available since 2.0 alpha version, you can also use Taxonomy Query, with the “Terms” set to {post_terms_product_cat:plain:term_id}. That way, you don’t need to manually select the category (like above), but you can query products dynamically, based on current product categories.
Thank You!
It’s live site, so i don’t use 2.0 alpha.
“so, to show products only from one category, you can use “Terms (include)” field:” - I need to show products, that belongs to specific category (age) subcategories. My structure looks like this:
Age
0-3
3-5
…
There is a lot more categories assigned to product, but i only need to query this specific category subcategories.
So, when user browse product that belongs to sucategory 0-3, i need to display products from that subcategory. If product is asigned also to 3-5 subcategory, i need to display both subcategories (in one query).
Did you allow the execution of the function? If you ouput the {echo:....} inside the basic text element, what is the output?
For your second question, it’s used for returning only posts from specific child. So, if your category “Age” has ID of 123, and you want to list all subcategories, you will add “123” to the custom term query loop.
Did you allow the execution of the function? - no… Thank’s for pointing out - now the query outputs the results
For your second question, it’s used for returning only posts from specific child - unfortunately, when I add the category id to the query, in the “child of” position, the query loop does not work again and does not display the results.
Yes, because you are querying the posts, but the ID you added to the “child of” field is from terms/category.
They need to be the same type, then it should work
I was in a hurry, it doesn’t work. And after thinking about it, it couldn’t have worked, because I didn’t give priority anywhere to the selected category that I care about.
Thinking further, how is this custom function different from the native functionality of the “Related products” checkbox? Probably nothing, but it displays different results…
The perfect scenario is where I can click the “related products” checkbox and select a category to prioritize, like in the image below. Unfortunately, this configuration doesn’t display anything.
Yes, because you are querying the posts, but the ID you added to the “child of” field is from terms/category. They need to be the same type, then it should work
Since I’m querying posts of the product type, the “child of” option shouldn’t be available, because a product can’t have a parent. This is misleading, or I don’t understand something.