Skip Navigation

[Resolved] Set default value of a relationship form field.

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by trulsD 2 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2263555

Hi.
On my website, I have a CPT called organization. An organization has only one "Master user" but can have multiple "Guest users."
I have a relationship form that lets a"Master user" choose another user to become a "Guest User" in his organization.
Is there a way to have the relationship form field for the organization pre-selected? I want to hide the organization dropdown so a "Master user" can not choose an organization other than the one the "Master user" is related to.
I have made a PHP function that gets the organization id of the "Master User."
I have tried to use jquery to pre-select a value from the dropdown, but I am unsure how to target the "select" in the form.
Can you point me in the right direction?

truls

#2264275

Hi,

Thank you for contacting us and I'd be happy to assist.

You can pass the target post's ID in the relationship form's shortcode, to make it pre-selected.

For example, suppose you have a relationship form with slug "form-to-connect-posts" and the "organization" CPT is the parent in the relationship. To make the "organization" post with ID "123" pre-selected, you can insert the form using the shortcode:


[cred-relationship-form form='form-to-connect-posts' parent_item='123']

Similarly, if the "organization" CPT is the child in the relationship, the shortcode would be:


[cred-relationship-form form='form-to-connect-posts' child_item='123']

If you have a PHP function that returns the target "organization" post's ID, you can register a custom shortcode for it ( ref: https://codex.wordpress.org/Shortcode_API ) and then use it as a value for the "parent_item" or "child_item" attribute, as needed.

Note: After registering a custom shortcode, please include it in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2264357

My issue is resolved now. Thank you!