Skip Navigation

[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:

function child_exists_func( $atts ){
    extract( shortcode_atts( array(
        'child_post_type_slug' => '',
    ), $atts ) );
    $child_posts = types_child_posts($child_post_type_slug);
    if ($child_posts) {
        return true;
    }
}
 
add_shortcode( 'child-exists', 'child_exists_func' );

2. Register the ‘child-exists’ shortcode first in Toolset >> Settings >> Front-end Content >> Third-party shortcode arguments.

3. Then add this shortcode in your View >> Loop Output Editor:

 [wpv-conditional if="( '[child-exists child_post_type_slug=belong]' eq '1' )"]
[wpv-post-link]
[/wpv-conditional] 

==> Where as “belong” is your child post type slug that you should replace.

This support ticket is created 6 years, 8 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.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 15 replies, has 3 voices.

Last updated by Noman 6 years, 8 months ago.

Assisted by: Noman.

Author
Posts
#559936

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

This ticket is marked as resolved and closed for new messages.

Please open a new ticket for this 2nd issue with some more details and we will handle this issue separately. This will help other users with similar problems to find solutions when searching the forum, as per support policy. https://toolset.com/toolset-support-policy/
You can assign the new ticket directly to me if you want.

I would be happy to help you.
Thank you

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.