Tell us what you are trying to do?
I've CPT called Look Book which has many-to-many relationship with 'Products' CPT
Relationship Name is: 'Look Books Products' (slug: look-book-product)
Some of the products have associated post from Look Book CPT.
I have a view that i want to filter and show only those products which have associated look book items.
PFA screenshot.
p.s.: Please note i don't want nested view. I only want to filter products have look book items.
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site?
Hello and thank you for contacting the Toolset support.
I would suggest setting the view to query the intermediary post type of the relationship, and inside of the loop use the item-attribute or the dynamic sources(using blocks) to display the parent product post.
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/
Note that you might have duplicated products, especially those linked to more than one Look Book post.
Otherwise, you can implement a custom code solution using the Toolset Relationship API, or our extension to the WP_Query arguments:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts
I hope this helps. Let me know if you have any questions.
Hi Jamal,
I'm still confused and can't comprehend how to implement this.
I've already created a view that queries products.
I just want to find out if there exists a relationship. i..e I only want to pull the products that have associations.
I've a problem which is opposition of the problem over here:
https://toolset.com/forums/topic/views-within-a-view/#post-1784287
In the above code, it excludes posts with specific relationship. I want code which only 'includes' posts with specific relationship.
You can use a similar code to that example https://toolset.com/forums/topic/views-within-a-view/#post-1784287
By changing lines 25-27. Instead of including only the post that do not have related posts, include only the ones that have a related post.
if( ! empty($products) ){
$include_ids[] = $showroom->ID; // push the related project IDs into this array
}
Does it make sense?