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.
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?
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?
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!
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?
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.