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?
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!
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.
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:
Task is assigned
<!-- wpv-loop-start -->
<!-- wpv-loop-end -->
Your CRED form will go here
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:
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)
The topic ‘[Closed] I need to make conditional that will test to see if there are any child posts’ is closed to new replies.