Hello,
i am trying to set a default value for a relationship field added to a post form by using the cred_filter_field_before_add_to_form filter.
I used successfully this filter when i needed to set a default value for a custom field (textfield) but i don't find a way to do the same with a relationship field (adding a value to default_value attribute seems useless).
How can this be accomplished?
Thanks for the help.
So that I understand the requirements correctly, is it that each form will have a different default parent value ?
Reason for the question is because there is a default value option on the form for you to set the ID of the parent post that you would want to be the default parent. See Screenshot.
Thanks for the answer.
I need to set the default value via PHP.
Just for example, imagine that i need to set a random default value (obviously from al the options of the select) each time the page is loaded.
I did a quick test on this one for you with a custom shortcode providing the value attribute and it works.
What you can do is to write a custom shortcode using the shortcode generator at the link below. hidden link
At the end you should be returning a post ID from the parent post type. Once you've done this just add the custom shortcode to the value attribute of your relationship field and it will automatically select the parent post.