Skip Navigation

[Resolved] Create view for posts with no related posts

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Shane 7 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#525757

I'm trying to create a view that will show posts that have no related posts.

E.g.

Three CPTs: Book, Chapter, Page

I want to create a view for that will display chapters that do not have any pages.

I tried to create a view on chapter, then a conditional based on another view for page but the nested conditional statements don't work.

This looks similar but is related to parent/child posts: https://toolset.com/forums/topic/child-if-children-exist/

Is there a quick/easy way to modify the shortcode to apply to this scenario?

#525792

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi John,

Thank you for contacting our support forum.

We can adopt this for you.

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

To use the shortcode you will need to pass the slug of the child post type into the shortcode. Example [child-exits slug='my-child-cpt']

Next you will need to register the shortcode so that it can be used in our views conditional shortcode. To do this go to Toolset->Settings->Frontend Content and add 'child-exists' to your 3rd party shortcode arguments section.

Finally this shortcode will return nothing when there is no children available.

So you will do then need to evaluate this shortcode using our wpv-conditional which can be seen in the link below.

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

Please let me know if this helps.
Thanks,
Shane