As I’m unsure if I was using the correct terminology in my previous attempt for support, I have listed a summary and a step by step group of images. So before we get into how I’ve attempted to do it, I’d like to know if it is even possible.
What I’d like to do:
I would like to create a 2 step Product Filter based on a one-to-many relationship then based off of a custom field in the result of the one-to-many result which is >= a product attribute.
Current thought process:
There is a “one to many” relationship between Make & Engine
1) Select Make via dropdown
2) Select Engine via dropdown
Engine has a custom field called Max CFM (Airflow). Products also have an Attribute called CFM (Airflow).
I would like the results of the filter to be something like engine.cfm >= product.attribute
Thanks in advance.
Hello,
I assume we are talking about this case:
Three post types:
- Make
- Engine (with custom field "Max CFM")
- Woocommerce products (with attribute "CFM ")
One-to-many relationship between post types "Make" and "Engine".
And you are going to setup a custom search form with two dropdown menu:
- Select Make
- Select Engine
Then display product posts whose attribute "CFM" value are <= field "Max CFM" value of Engine post.
If it is, it is not possible within your current post type structures. since in the Toolset Views search form, in order to build two dropdown menus, the post type relationship filters requires third child post types, but in your case, there isn't post type relationship with Woocommerce products.
So I suggest you try these:
1) Create a post type relationship between post types "Engine" and "Woocommerce products", you can try with one-to-many or many-to-many relationships, that depends on yourself. If:
- one "Engine" post can connect to multiple "product" posts,
- one "product" post can connect to multiple "Engine" posts,
I suggest you try with many-to-many relationships
see our document:
https://toolset.com/documentation/post-relationships/
2) Then you will be able to setup the a post view:
- Query "product" posts
- filter by post type relationships:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/
- Then display the related "product" posts information in view's loop.
Hi Luo,
You’re correct on what I’m trying to achieve, however the CFM filter is critical.
With your instructions I don’t believe a many-to-many (engine to product) relationship would work (I did try) as there will be hundreds of engines and at least a dozen products and directly linking them like Make / Engine is not an option.
If this isn’t possible with my current post type structure, how should I proceed?
There isn't such kind of built-in feature within Toolset Views plugin, you might consider the custom codes, for example:
1) In the custom search form, build the "Make" and "Engine" dropdown menus manually.
2) user choose an option in "Engine" dropdown menu, and submit the search form, pass "Engine" post ID as URL parameter.
3) use filter hook "wpv_filter_query" to trigger a PHP function:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
4) in this PHP function, get the "Engine" post ID from URL parameter, and get the field "Max CFM" value of Engine post, use it to filter the query:
https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters