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
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
My issue is resolved now. Thank you!