I have a Ride Notification post form on our Ride pages. There is a relationship established between these two content types.
When I submit a new Ride Notification through the post form, it works 100% as expected. It establishes the relationship with the Ride and it displays through the view that I have set up to display all Ride Notifications for the current Ride through the relationship.
But when I submit a 2nd Ride Notification for the same ride through the post form, it only works at a level where the Ride Notification post is created. The relationship to the Ride does not happen.
The relationship between Ride and Ride Notification is defined as follows:
1 Ride can be assigned to one Notification Infinite Notifications can be assigned to one Ride
Limits
Maximum number of Rides possible to assign to one Notification
1
Maximum number of Notifications possible to assign to one Ride
Default: No limit
I'm guessing I have something defined incorrectly here, but I think this is how it should be set up. We want the ability to have many Notifications per Ride. But we also want each Notification to only be related to a single ride. No Notification should apply to multiple Rides.
Any thoughts on what I've done wrong here?
Hello,
How do you setup the post type relationship between "Ride" and "Ride Notification"?
One-to-many or many-to-many?
In your case, it needs just one relationship:
One-to-many between "Ride" and "Ride Notification"
See our document:
https://toolset.com/glossary/post-relationships/
section "One-to-many relationship".
And you can follow our document to setup the child post form for creating new "Ride Notification" post:
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/
I have it set as one-to-many already.
As far as the document you provided for setting up the child post form, I'm not sure if I did that correctly. This piece of the content template has been converted to HTML, so I can't see if I set up the form correctly. The code in the HTML is as follows:
<h3 style="color: #000000;">Send Ride Notification</h3>
[expand title="Click here to send Ride Notification"]<div class="wp-block-toolset-cred-form notification-form">[cred-form form="ride-notification-form"]</div>[/expand]
I did that so the form would not display on the page until after a link to expand it is clicked. That's functionality provided by another plug-in that can set content as collapsed until the link to expand is clicked.
I don't know how to get it back to see the steps shown here:
03. In the pop-up dialog, click Create Child Post Link.
04. Another dialog appears where you have to select the options for your link.
05. In the Parent post section, make sure to select the option Set the parent according to the currently displayed content.
I'm not sure what I chose there when I initially added the form the Ride template before converting that section to HTML. It's just pulling [cred-form form="ride-notification-form"] .
But the form is working fine to create the first notification. The relationship is established between Ride and Ride Notification as expected there. But then it won't establish the relationship for a second Ride Notification.
I didn't think I should make the relationship many-to-many because I want each Ride Notification to only apply to one Ride. But maybe I should have made it many-to-many. Any further thoughts?
When I click Expert Mode on the form setup, this is what shows there:
[credform]
[cred_field field='form_messages' class='alert alert-warning']
<div class="form-group">
<label for="%%FORM_ID%%_post_title">[cred_i18n name='post_title-label']NOTIFICATION TITLE[/cred_i18n]</label>
[cred_field field='post_title' class='form-control' output='bootstrap']
</div>
<div class="form-group">
<label for="%%FORM_ID%%_post_content">[cred_i18n name='post_content-label']NOTIFICATION CONTENT[/cred_i18n]</label>
[cred_field field='post_content' output='bootstrap']
</div>
[cred_i18n type="html" name="scaffold_field_id"]<div class="hidden-div">[/cred_i18n]
<div class="form-group">
<label for="%%FORM_ID%%_@ride-notification.parent">[cred_i18n name='@ride-notification.parent-label']Ride Notifications[/cred_i18n]</label>
[cred_field field='@ride-notification.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='false' value='[wpv-post-id item="$current_page"]']
</div>
[cred_i18n type="html" name="scaffold_field_id"]</div>[/cred_i18n]
[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]
I don't know if that provides any help at all, but I thought I'd let you see it in case it does help.
Thanks for the detail, in the child post form you mentioned above:
[cred_field field='@ride-notification.parent' class='form-control' output='bootstrap' select_text='--- not set ---' required='false' value='[wpv-post-id item="$current_page"]']
This is post type relationship field, it should be able to use current "Ride" post ID as default value, and you need to display this child post form in single "Ride" post.
If you need more assistance for it, please provide a test site with the same problem, also point out the problem page URL, provide detail steps to reproduce the same problem:
when I submit a 2nd Ride Notification for the same ride through the post form, it only works at a level where the Ride Notification post is created. The relationship to the Ride does not happen.
Private message box enabled.
Thanks for the details, I have tried these:
1) Login into your website with user "Toolset", check the URL you mentioned above:
hidden link
I can not see the child post form "Ride Notification Form",
2) In order to test result, I have edited the content template "Template for Rides", add a shortcode block, display the child post form shortcode directly:
[cred-form form="ride-notification-form"]
3) Test it again in frontend:
hidden link
Fill and submit the child post form, return back to above URL fill and submit the form.
It works fine, I don't see the issue you mentioned above: The relationship to the Ride does not happen.
Is there any missing steps?
Hmmm, that's very odd. I tested using the form you added and it worked. So I then tried testing using the form I had before and it worked too. So now I've removed the form you added. I've done multiple tests on my form and they all worked. I'm having some others on the board of the club test this on their end now.
I can't explain why it wasn't working before but is working now. It definitely wasn't working though.
Maybe your involvement just intimidated the form into working properly. It may have said "Uh oh, Luo is here, better stop messing with Kenny.'s mind now." 😉
However you reporting that you could not see the form when you were logged in as the Toolset user is also problematic. Can you go to this Ride page again:
hidden link
Please tell me if you see a heading saying "Send Ride Notification" and a link under that saying "Click here to send Ride Notification". If you see that, then that means the conditional display is working as it should. If you don't see that then something is broken with that.
Then, if you do see that, tell me what happens when you click on "Click here to send Ride Notification". Does the form not expand? Do you see anything in there? If you don't see the form there, then something is wrong with the permissions for using the form.
I just had one of our board members do a test on his end and the relationship did not work on his FIRST test this time. You can see this ride here again:
hidden link
On that page, you can see 4 notifications present. 2 of those were submitted from my admin user account. 2 of those were submitted by me from a different user account that only has the Ride Leader role, but not the admin role. All 4 notifications worked perfectly for me now. The relationship was established on all.
But you can see his attempt at a test notification here:
hidden link
That one was submitted from his Ride Leader role user account, but you can see that the relationship didn't work for him. The credentials for his user account should be identical to the Ride Leader role account I used. I have no explanation for why it worked for me but not for him. I have no explanation for why it worked for you where it didn't work for me previously. I have no explanation for why it worked for me after you looked at it when it didn't work for me before. This weird inconsistency is baffling and very frustrating. Note that previously, it worked for him on his first test, but not on his second test. This time it didn't work on his first test. Is there anything you can think of that would cause this kind of inconsistent behavior from the relationship between Ride and Ride Notification? I've told him to clear his browser cache and to refresh the page before trying again. He'll do another test shortly.
OK, our board member just tried it again by sending two notifications and this time both of them worked perfectly. Maybe it was clearing the browser cache. Wow. Sorry for the difficulty here.
I'm now going to send another message to the rest of their board to get more board members to send test notifications on rides they are leading. I will make sure to tell them to clear their browser cache before trying this.
Please keep this ticket open until I see that it's working for everyone. I'll send another update here if I see more incosistencies where it isn't working for everyone.
OK, I have updated this thread status to "Waiting for feedback" status, please update here if you still need assistance for it.