Hi, thank you for reading.
I have a website with 2 custom post types: "keebs" and "keycaps"
keebs CPT has a custom field of "keeb-keycap-brand"
keycaps CPT has a custom field of "manufacturers"
Both custom fields are checkboxes that have the same options.
I would like it so when a user is on a keebs single page that there is a view on the bottom of the page that shows all keycaps CPT that match.
i.e. keebs CPT has "keeb-keycap-brand" of "Company1" I would like a view on the single view of this that shows all the keycaps CPT that have a matching "manufacturers" of "Company1"
Can I achieve this with toolset?
Hello,
In your case, it is a many-to-many relationship between post types "keebs" and "keycaps"
It is not recommended to a custom checkboxes field to setup the relationship.
In your case, you can try with a custom taxonomy, for example:
1) Create a taxonomy "keebs-keycaps", register it to both post types "keebs" and "keycaps"
2) In single "keebs" post, display nested view:
a1) Parent taxonomy view:
- query terms of taxonomy "keebs-keycaps"
- Filer by:
Taxonomy is set by the page where this View is inserted
- In views loop, display below child post view
a2) Child post view:
- query "keycaps" posts
- Filer by:
Select posts with taxonomy:
Categories set by the parent Taxonomy View
- In views loop, display "keycaps" post information
Thank You for your response. I fail to see how this does what I'm looking to do though. If I'm assigning all keycaps and keebs to the same category of keebs-keycaps how does it match up the manufactures and keeb-keycap-brand custom fields to query?
I think Shane helped another user out with a similar issue: https://toolset.com/forums/topic/filter-view-by-shortcode-based-on-custom-field-values/
Maybe we could loop them in?
I got it to work through your suggestion. I was confused with the taxonomy at first, but I got it to work! Thank You. I'll reach back out if I have any other issues.
Ran into another issue. When I have a CPT that has multiple categories in one taxonomy. Let's say the taxonomy is "keebs-keycaps-colors"
When I have a keeb that has multiple colors like blue and gray. The parent/child view shows 2 views. 1 for blue and one for gray. I would like them combined into 1.
Yes, it is possible with only one post view, see below sandbox website.
Login URL: lien caché
1) Post view:
- Query keycaps posts
- Filter by:
Select posts with taxonomy:
keebs-keycaps-colors the same as the page where this View is shown
- In view's loop, display keycaps post in formation
2) Test it in single keebs post:
lien caché
It works fine
For your reference.
Thank You. That worked great!
Is there a disadvantage/advantage to using either method?
Also can I control if it's an AND or OR relationship for the view?
The first method is using nested views, the second one is just one post view, you can choose one of them depends on your need.
You can customize the AND or OR relationship by following our document:
https://toolset.com/de/course-lesson/filtering-custom-lists-of-posts/#filtering-by-taxonomy
And you can use wpv_filter_query filter to customize the taxonomy filters:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
Thank You for those. In the first link it only shows how to do it when you are setting the categories directly, not if they are set by the page the view is being used on.
The "And or Or" option only available when you add multiple taxonomy filters, see my screenshot