I have two CPT, album (parent) and product (child), I want to create a view that only displays albums who have a child (product). I do not find how to do the query filter in my view ? Can you enlighten me on this point?
There is no way using a standard View (built upon WP_Query) to filter parent posts by how many child posts they have.
You would need to use a combination of the Toolset APIs to achieve this.
You have a View which queries the parent post type (which may include various filters, such as a taxonomy filter, unrelated to this particular issue).
This will return parent posts whether or not they have child posts.
You would then modify the query results before they are output by the View using the wpv_filter_query_post_process filter.
(hidden link)
You would loop over the query results and for each parent post use the toolset_get_related_posts function to get the child posts. If there were none, you would remove the parent post from the results.
The difference is that this was before Types 3 and was based on Types 2 relationships. So you would need to change the "//get the child posts of the parent" section to use toolset_get_related_posts instead of get_posts.
If you want to try that let me know how you get on, and if you get stuck I'll help (the support queue is very busy at the moment so it may be a while before I can provide such code).
I do not quite understand what I have to do.
My problem is similar to this one (https://toolset.com/forums/topic/displays-only-posts-with-less-than -3-children / # post-452734) but in reverse (only shows if there are children) At the moment I have a view that shows all the albums and I would like it to display only albums that has at least child.
The following code seems to be the right track but I do not know how to use it to do the opposite ?
The function would then become "min-post" in place of "max-post"
I need some clarification :
where do I have to encode the ID of the view ?
And I dont know where I can get the slug of the relationship. It seems that I dont use it because I still work on the old toolset plugin method.
I have a page that asks me if I want to do the migration? (see screenshot) Will it not damage my site?
Thanks a lot
OK, sorry, if your site is not using Types 3 relationships it is not necessary to migrate, but the code I offered in the last reply needs changing back to use the old method.