Skip Navigation

[Resolved] I need to make conditional that will test to see if there are any child posts

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 support ticket is created 7 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 7 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#576897

Based on this ticket:

https://toolset.com/forums/topic/i-need-to-make-a-button-for-users/

I need to know how to make conditional in LAYOUT that will test to see if there are any child posts?

It the post has any child post layout should show some text like "Task is assgined". If not, it should show form (button) with ability to create new child post for it.

#577111

Hi, I would use a View to handle this. Create a View of posts filtered by post relationship, where the parent post is set by the current page. If any results are found, show "Task is assigned". If no results are found, show your form instead of the standard "No results found" message. Would this work for your requirements?

#577335

But I need button inside the single post. After people see the list op posts, they click on one particular post and should see the button if the post is not assigned. Is it possible to o that?

#577452

But I need button inside the single post. After people see the list op posts, they click on one particular post and should see the button if the post is not assigned. Is it possible to o that?
This sounds like a separate issue from creating a conditional, so it's best to create a separate ticket for the form and button question. The general idea for creating a form with a button is to use CRED, our content creation and editing plugin, to edit a post. More information about CRED here:
https://toolset.com/documentation/user-guides/creating-cred-forms/

If you need more detailed information, feel free to open a separate ticket and ask direct questions about CRED. Thank you!

#577601

In this post: https://toolset.com/forums/topic/i-need-to-make-a-button-for-users/

You said:
In your Content Template for Tasks, you will place your CRED form inside a conditional. That conditional will test to see if there are any child posts of the current Task. If not, you will show the form so someone can click the button and assign the task to themselves. If a child post exists, then you know that the Task has already been assigned and you can show a different message instead of the form.

I just want to know how to do that?

#577722
new-view.png

Oh okay, you already have the ticket started - great! I forgot about that, sorry. Here's how to use a View as a conditional that tests to see if there are any child posts:
1. Create a View of your child post type. See new-view.png.
2. Filter this View by Post Relationship, where the post parent is the current post. See new-view.png.
3. In the Loop Output editor, paste the following code:

[wpv-layout-start]
	[wpv-items-found]
    Task is assigned
	<!-- wpv-loop-start -->
	<wpv-loop>
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		Your CRED form will go here
	[/wpv-no-items-found]
[wpv-layout-end]

You can see here that the conditional is already part of the View - wpv-items-found vs. wpv-no-items-found.

4. Place this View in a Visual Editor cell in the parent post type Layout:

[wpv-view name="your-view-slug"]

5. Next, create your CRED form and replace the text "Your CRED form will go here" with the shortcode to display that CRED form.

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