[Resolved] I need to only display parent posts that actually have children
The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This thread is resolved. Here is a description of the problem and solution.
Problem:
Trying to create a page that Lists only the parent posts that actually have Children, not all the parent posts.
Solution:
1. Add this code in your theme’s or child theme’s functions.php file:
==> Where as “belong” is your child post type slug that you should replace.
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 community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
Tell us what you are trying to do?
I'm trying to create a page that lists only the parent posts that actually have children, not all the parent posts.
The code for my template of this view looks like this:
I know I need to wrap this in a conditional of some kind, but I just cannot get it working....
Is there any documentation that you are following?
I have looked at a number of support threads and think that this one is the closest to what I need https://toolset.com/forums/topic/conditional-html-check-if-post-has-children/
, but as soon as I apply the conditional my parent post title no longer displays, just the child posts.
Is there a similar example that we can see?
What is the link to your site?
The current page I am trying to create is here: hidden link
Thank you for contacting Toolset support. I am working on this right now and I will update you with my findings shortly. If it can’t be done using View shortcodes, then I might need to add some small code to achieve this. Please wait and I will update you accordingly.
2. Register the ‘child-exists’ shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments. See attached screenshot.
3. Then add this shortcode in your View >> Loop Output Editor:
I need to take a look at your setup and to request temporary website WP-admin and FTP info for your site to debug further and to help in resolving this. Your next answer will be private which means only you and I have access to it.
=== Please backup your database and website ===
✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.
All you have to make sure is:
- Change the “belong” to your child post type slug with your child post slug / name.
- Make sure you have registered the given shortcode first.
- And make sure to add it in active theme's functions.php file.
Just a question though as it would be good to know exactly what you had to change.
1. What changes did you make to the functions.php file, if any?
2. What changes did you make to the conditional, if any?
3. Did you have to change anything else in the way that I had it configured?
1. What changes did you make to the functions.php file, if any?
==> Nothing, just added the code in functions.php file, as I saw it was not there.
2. What changes did you make to the conditional, if any?
==> Just changed, the “belong” child post type slug with your child post slug / name like this: