Skip Navigation

[Resolved] Display Products Based on CPT Relationships – List not narrowed by criteria

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Author
Posts
#558341
wphelp.JPG

I am trying to:
Show Products that are compatible by Manufacturer and Model
Current Site Example is - hidden link
Use Nescon > XBroom as example as I am still mapping out relationships.

Link to a page where the issue can be seen:
hidden link
Once filters are selected all of the products are shown.

I expected to see:
Only the details of these products:
01-100360PW
04-100360PC
06-100360WW
09-100360WC
15-SPACER10
41-PATELP5H
41-PATELP5
41-POELP5

Instead, I got:
All products.

Am I making this too complicated? Please point me in the right direction.

#558422

Dear Sarah,

Thanks for the details, I can login your website, and I can see the problem, I need your permission to deactivate plugins and switch theme, please back your database first.

#558603

The core site files and sql are backed up.

Please note that XPro (theme) is powering the rest of the site. Please clarify why you need to switch themes. I was under the impression that Toolset was compatible.

#558825

Thanks for the details, I am checking it in your website, will feedback if there is anything found

#558826

Here are what I found:
1) You are using below post type structures:
Grandparent post type "Product"
-- Parent post type "Model / Sizes"
---- Child post type "Compatibilities"

I did below modification in your website
2) In the problem view, section "Content Selection", you are querying four post types:
Products + Compatibilities +Model / Sizes + Product Types
It is not needed, and it is confused, what post do you want to query?
in your case, it needs only enable option "Compatibilities"

3) in section "Ordering", change it to post title.

4) in section "Templates for this View"
those custom fields belong to post type "Product", for example,
[types field='bf-part-type' id='$model-size-post'][/types]
This line should be:
[types field='bf-part-type' id='$product'][/types]

#559045

Great. This direction got me almost there!

For this page
hidden link

There is one additional filter (product type) that needs to be select first to then narrow down the manufacturer.

Product type is a custom field for the product.

Thanks again for your direction as I learn this tool.

#559401

Views plugin is using wordpress class WP_Query to query the posts:
http://codex.wordpress.org/Class_Reference/WP_Query

If you are querying posts of the child post type "Compatibilities", you can only filter the view by the custom fields and custom taxonomies of "Compatibilities", since the "product type" is a custom field of another post type "product", so the additional filter (product type) will not be able to work, and there isn't such a feature within Views plugin.

#559408

Would it be a possibility if it were a cpt with a parent child relation with another common cpt?

Product type .. use ... manufacturer

manufacturer >model .. compatibility ... product

Trying to create the product type option on this page.

hidden link

#559414

Yes, it is possible, you will need to create another new post type "product type", setup it as parent post type of:
a) Compatibilities
b) Products
That will be able to make those three dropdown menus work.

And there is a workaround, you can add a custom taxonomy "product type" into post type "Compatibilities", edit each "Compatibilities" post, setup the term of each "Compatibilities" post, then you will be able to setup the taxonomy "product type" filter in your view
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/

For your reference.

#559790

I think I have the relationship set up correctly but am unsure how get the 3rd product type/use active with many and model.

#559799

I can see you have already change the post type structure in your website, there isn't any relationships between post types "Product" and "Model / Sizes", which is different from this post:
https://toolset.com/forums/topic/display-products-based-on-cpt-relationships-list-not-narrowed-by-criteria/#post-558826
Grandparent post type "Product"
-- Parent post type "Model / Sizes"
---- Child post type "Compatibilities"

since the original question is resolved, please create new thread for the new question:
I think I have the relationship set up correctly but am unsure how get the 3rd product type/use active with many and model.

Describe detail for these:
1) the post types relationships you want setup
2) Which filter do you want to setup in the custom search form.

That will help other users to find the answers. thanks

#560143
Find your broom.JPG

In summary for others to refer to:

Custom Post Types:
Manufacturer - with children compatibility, model/size
Model/Size - with parent manufacturer, children compatibility
Compatibility - with parents manufacturer, model/ size and product (woocommerce post type)

For each product I added a compatibility with the manufacturer and model/size indicated.

Views - Filter product records by manufacturer and cascading/applicable model/size
content selection: post type > compatibility
query filter: post relationship filter > children of post with ID set by URL parameter

Filter Editor (with some Theme X by Theme.co shortcode markup)
************
[wpv-filter-start hide="false"]
[wpv-filter-controls]
[wpv-control-post-relationship ancestors="manufacturer-post>model-size-post" url_param="wpv-relationship-filter"]

[cs_section]
[cs_row inner_container="false" marginless_columns="true" style="margin: 0px;padding: 0px;"]

[cs_column fade="false" fade_animation="in" fade_animation_offset="45px" fade_duration="750" type="1/3" style="padding: 0px;"][x_raw_content]
<label> [wpml-string context="wpv-views"][/wpml-string]</label>
[wpv-control-post-ancestor type="select" default_label="Manufacturer" ancestor_type="manufacturer-post"]
[/x_raw_content][/cs_column]

[cs_column fade="false" fade_animation="in" fade_animation_offset="45px" fade_duration="750" type="1/3" style="padding: 0px;"][x_raw_content]
<label>[wpml-string context="wpv-views"][/wpml-string]</label>
[wpv-control-post-ancestor type="select" default_label="Model" ancestor_type="model-size-post"]
[/x_raw_content][/cs_column]

[cs_column fade="false" fade_animation="in" fade_animation_offset="45px" fade_duration="750" type="1/3" style="padding: 0px;"][x_raw_content]
<span style="float:right;">[wpv-filter-reset]</span>
[/x_raw_content][/cs_column]

[/cs_row]
[/cs_section]

[/wpv-control-post-relationship]

[/wpv-filter-controls]
[wpv-filter-end]
************

Loop Output - pulling custome post fields applied to product record
************
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<table width="100%">
<thead>
<tr>
<th>[wpv-heading name="types-field-bf-part-type"]Part Type[/wpv-heading]</th>
<th>[wpv-heading name="types-field-part-description01"]Part Description[/wpv-heading]</th>
<th>[wpv-heading name="types-field-part-number"]Part Number[/wpv-heading]</th>
<th>[wpv-heading name="types-field-number-of-bars"]# of Bars[/wpv-heading]</th>
<th>[wpv-heading name="types-field-number-of-rows"]# of Rows[/wpv-heading]</th>
</tr>
</thead>
<tbody class="wpv-loop js-wpv-loop">
<wpv-loop>
<tr>
[wpv-post-body view_template="Loop item in List of Compatible Product for Model Page"]
</tr>
</wpv-loop>
</tbody>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"] [/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
**************
Loop Code

<td>[types field='bf-part-type' id='$product'][/types]</td>
<td>[types field='part-description01' id='$product'][/types]</td>
<td>[types field='part-number' id='$product'][/types]</td>
<td>[types field='number-of-bars' id='$product'][/types]</td>
<td>[types field='number-of-rows' id='$product'][/types]</td>