I am trying to:
I'm setting up a website where products are grouped in a few layers (post types). The layers/post types are: Product category > product group > product sub group > products
To illustrate, an example could be:
Vehicles (category) > personal transport (product group) > Vans (sub group) > Ford C-MAX (product)
The thing is, not every product has a sub group (or potentially product group) it is assigend to, so it could be necessary to display all products under the product group, for example:
Vehicles (category) > commercial transport (product group) > MAN TGX (product)
Notice: sub group is skipped in this example.
So what I thought of is adding a checkbox to the post types category, group and sub group that says "check to display products". If this is checked, the view should display all products that are childs.
For example, what the "product group" view should do: if checkbox = false show all sub groups assigned to it, if checkbox = true show all products assigned to the product group.
Unfortunately, I'm not too experienced with WP-Types yet so dispite trying for a few hours and searching the forums I couldn't find a solution, so I really hope someone can point me in the right direction.
Thank you very much!
I visited this URL:
I expected to see:
Instead, I got:
I do not understand how you are setting up your Contents.
Please, can you elaborate what you mean by "SubGroups", "product Group", and so on?
In Toolset there are Post Types, Post Fields, Taxonomies, Term Fields and Users/User Fields.
https://toolset.com/documentation/user-guides/create-a-custom-post-type/
https://toolset.com/documentation/user-guides/create-custom-taxonomies/
https://toolset.com/documentation/user-guides/using-custom-fields/
https://toolset.com/documentation/user-guides/term-fields/
I assume, but am not sure, that you have a Post Type (products), and assigned a Hierarchical Taxonomy (Product Group) to it.
This taxonomy has Parent and Child terms (Vehicles, Vans).
It also has a CheckBox (Term field) that can hold information like "check to display products".
Your final goal is to display in a View the Post Type "Products" with the Terms "Vehicles, Vans", but only if the checkbox "check to display products" is checked.
The thing is, this seems overkill to me.
If you want to display Posts with a certain Term (to display) you do not have to add a Field to that Term.
In any case, a Field can be set for one term only a time.
The Same Term can not have a second value, as the term exists only once.
Furthermore, the Terms' fields can be used only in Taxonomy Views, not in Post Views.
My suggestion is that you create either a Custom Field or a Taxonomy that lets you choose "to display" or "not to display" and do then use the Query Filter in your Post view to display the correct content.
https://toolset.com/documentation/user-guides/views/
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
Please let me know if I misunderstood you.
Hi Beda, thanks again for taking the time to help me out!
I was afraid I didn't really make the issue clear, it's a bit hard to express.
Every "layer" is a post type. So there is one post type for Categories, Product Groups, Product Sub Groups and Products (hidden link).
I'll try to illustrate what I would like to achieve: I first create a [category post type] -Vehicles-.
and enter all the information in the form. Then I create a [product group post type] -Personal transport- and assign -Vehicles- as a parent. Then I create a [product sub group post type] -Vans- and assign -Personal Transport- as a parent. In the last step, I add the [product post type] -Ford CMAX- and assign -Vans- and -Personal Transport- as parents.
Now by default, -Vehicles- would list all [product groups] assigned to it, -Personal transport- would list all [product sub groups] assigned to it and -Vans- would list all [products] assigned to it.
When I check the checkbox "show products" at -Personal Transport-, it should skip showing the [product sub groups] and instead directly show all [products] assigned to -Personal Transport-.
My issue is that our client has different hierarchial structures for different categories (for example a very deep assortment of Screens (for private/commercial use, then grouped by size, then by technology,...) but a very flat assortment of plugs (Category plugs would show groups "single" or "multiple" and then already the products). If it helps, I can send you a link to his current website (I would rather do so in private though and it's German).
Thanks again for taking the time, I'm learning a lot using Wp-Types!
Thank you for your clarifications.
1. Now by default, -Vehicles- would list all [product groups] assigned to it, -Personal transport- would list all [product sub groups] assigned to it and -Vans- would list all [products] assigned to it.
- If you mean the WordPress backend, yes, and the only Settings to customise the Child Posts table would be in Toolset > Post Types > your_post_type > Post relationships (Parent / Child) > Children Post Types > Select Fields.
And it does not include a setting as you would need.
- I strongly assume, you mean what is displayed in a View, that displays Child posts of a current Post or a post set in a parent View.
There, this is also true, but it should be possible to achieve your goal, see below.
2. When I check the checkbox "show products" at -Personal Transport-, it should skip showing the [product sub groups] and instead directly show all [products] assigned to -Personal Transport-.
- Try to create a View, that displays your Parent posts (Vehicles as example)
- Then, you create a Query Filter in this View that simply shows only posts where your checkbox has the desired value (show products==true).
- After, you create a second View, which displays Posts that are set as child of the posts set in the parent View. (It will display the Sub Groups)
- You insert this second view in the first and the first into a page.
- Then, you create a third view, which finally displays Products (also set to display Products that are child of the post set in the parent view), and insert it in the second View.
This would create a List of Posts that are grandchildren to the Vehicles, but only if the Vehicles post has the checkbox "Show products" set to true.
You can read more about nesting Views here:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/
Hi Beda,
thanks for your answer again. I tried your solution and a couple of other things last week. I think I'm getting close but somehow it isn't working right now.
I simplified the whole issue a bit to make it easier to solve:
So I have 4 Custom Post Types:
- Categories
- Product Groups
- Sub Groups
- Products
I want to display the following:
In categories, all Product Groups of the parent Category should be listed - I've done that already.
In Product Groups, all Sub Groups of the parent Product Group should be listed. In some cases it doesn't make any sense to go that deep so i need to add a 2nd possible display option:
When the parent Product Group doesn't have a Sub Group --> Display the Products of the Product Group instead.
Therefore I did the following already:
- Product Groups have Sub Groups AND Products as child post types
- Products have Sub Groups AND Product Groups as parent post types
- In Product Groups there is a checkbox "this Product Group doesn't have a Sub Group"
Basically what I really need is to create a conditional output for the Product Group View right? "Display the Product if the checkbox is checked and display Sub Groups if the checkbox is unchecked"
Therefore I used a similar code as suggested in this topic: https://toolset.com/forums/topic/issues-checking-for-types-checkbox-fields-with-wpv-if/
This is my first line of code for the skip condition:
[wpv-if checkbox-produktuntergruppen="wpcf-checkbox-produktuntergruppen" evaluate="$checkbox-produktuntergruppen = '1'"][types field='produkttitel'][/types][/wpv-if]
Unfortunatly no products are shown in Product Groups anymore --> so something is wrong with the code I guess.
The 2nd line of code would be pretty similar I guess right?
I hope I could simplify and clarify the issue a bit. Thanks for the help so far!!
Best wishes
Manuel
wpv-if is not suggested anymore.
To check the status (value) of a Single Checkbox, please use the GUI "Conditional Display" (a button you find wverywhere in the Editors when Views is active)
Then choose Types Fields as source, and check the Field you need (checkbox-produktuntergruppen)
Set your condition and click insert.
That's it.
I paste below a sample code.
Note, my Checkbox is named "Checkbox-Single" and stores "1" if checked, nothing if not checked.
[wpv-conditional if="( $(wpcf-checkbox-single) eq '1' )"]
//things in here are displayed only if Checkbox Is checked (1)
[/wpv-conditional]
See also the screenshot.
If you need to evaluate this CheckBox while on a Child Post, so you need to check if the PARENT has that checkbox checked, you simply add "id="$parent_post_type_slug_here" to the ShortCode, and use Views Shortcodes instead of types ShortCodes, as in this example:
[wpv-conditional if="( '[types field='checkbox-single' id='$parent-type'][/types]' eq '1' )"]
//Things in here display only if the PARENT checkbox is checked (1)
[/wpv-conditional]
Thanks a lot!!
I tried it with conditional before but it didn't work - the partent-type-id did the trick!
Best regards
Manuel