[Waiting for user feedback] I need to make conditional that will test to see if there are any child posts

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.

Our next available supporter will answer your ticket in about 2.57 hours from now. Thank you for your understanding.

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.

This topic contains 5 replies, has 2 voices, and was last updated by  Christian Cox 1 week, 3 days ago. The support staff assigned to this topic is Christian Cox.

Viewing 6 posts - 1 through 6 (of 6 total)
Author
Posts
#576897

Based on this ticket:

https://wp-types.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

Christian Cox
Forum moderator

Supporter languages: English (English )

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

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

Christian Cox
Forum moderator

Supporter languages: English (English )

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

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://wp-types.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://wp-types.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

Christian Cox
Forum moderator

Supporter languages: English (English )

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

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.

Viewing 6 posts - 1 through 6 (of 6 total)

You are not logged in. You can view support threads, but not post.
If you are already logged in, please refresh your browser.