Tell us what you are trying to do?
I have a generic select field in a CRED form. I get the options from a shortcode. Works everything fine so far. I use the generic select field to connect the newly created post with another post. Additional to that, I need to save the "label" of the choosen option in another single line input field. I know how I can save the value of the option - but unfortunately I need the label and not the value. Any ideas?
I use cred_save_data hook and that's the code so far...
update_post_meta( $post_id, 'wpcf-activity', $_POST['select-activity']['label'] ); ---> it doesn't work 😉
Is there any documentation that you are following?
Something similar to this, just that I use it in a slightly different context:
https://toolset.com/forums/topic/assigning-the-post-to-a-user-on-the-front-end/
Is there a similar example that we can see?
In the documentation, but without the "label" problem. They only access the value ...
What is the link to your site?
hidden link
Hello,
I think there is a misunderstanding, after user submit the form, in server side, you can get only the select option value, you can not get the option label setting, so you consider to move option label value into select option value settings.
More help:
hidden link
The thread you mentioned above:
https://toolset.com/forums/topic/assigning-the-post-to-a-user-on-the-front-end/
It is for changing the post author with user's ID, so after the post author is changed, in the post content, you can display post author nickname with shortcode:
[wpv-post-author format='meta' meta='nickname']
So I don't think you need to pass user's nickname to your custom PHP codes.
Many thanks Luo and many appologies for the delay.
I found a workaround.
My issue is resolved now. Thank you!
Workaround:
add_action('cred_save_data', 'terminserie_erstellen_mad',10,2);
function terminserie_erstellen_mad ($post_id, $form_data) {
// if a specific form
$forms = array( 47490 );
if (in_array($form_data['id'], $forms)) {
//get the value of the field, that is shown in the generic dropdown as "label" from the corresponding activity post
// the $_POST['generic-select-field'] represents the id of the corresponding activity post
$label = get_post_meta($_POST['generic-select-field'],'wpcf-acitivty-name',true);
// update the field in the newly created post with the value from the label
update_post_meta( $post_id, 'wpcf-field-that-should-contain-label-value', $label);
//connect the newly created post with the corresponding acitivity post, where "acitivity-rask" is the relationship slug
toolset_connect_posts( 'acitivity-rask', $_POST['generic-select-field'], $post_id);
}
}