[Resolved] Exclude all Posts whit no Children in a View
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to filter parent posts having no child or How to display only parent posts having no children
Solution:
To display the only parent post not having any child post, You need to use the view's query filter: wpv_filter_query in conjunction with the Toolset post-relationship API function where using post-relationship API function toolset_get_related_posts() you will be able to find the child posts based on the specific parent post.
In my project I have a producer and products with a parent (producers) and child (products) relation. In the view, in which I show the producers, I want to hide all posts that have no children. Can you help me to find the right query filter?
This is the Site where the view is displayed: hidden link
Hello. Thank you for contacting the Toolset support.
There is no way to display the parent post not having the child post directly. You need to use the view's query filter: wpv_filter_query in conjunction with the Toolset post-relationship API function.
As you are using filters as well with your view so its hard to find the only posts which do not have any child as we need to consider the search input as well.
Can you please share access details so I can review your setup and check what is the best way to implement it.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I see you reusing the text search and you can do filter the view using ajax when you add a text search, that is why I've added the search button and with full refresh when you click on the search button.
I've added the following code to the "Custom Code" section offered by Toolset to filter the posts who do not have any child.
=> hidden link
I do not see the posts you marked with the border. Can you please tell me on what page I can see those posts? Do I need to apply any filter?
Is there a special reason why you changed the search to full page load? The search box worked just as well with Ajax.
==>
Yes, as you are using text search, text search do not support ajax search and it needs search button that is why you need to go with search button.
I don't see the posts anymore either, so we can conclude that there are no more posts displayed that don't have children. Thank you very much for the excellent support. Have a nice day.