It works and the values get saved, the only thing is that i have both options showing up and i need the first option only in the first field, while the second option show up on the second field
I think the least hacky way to do this is to add connected radio inputs wherever you want them in your form directly (i.e. in expert mode on the form write the actual input tags rather than inserting the input using a cred field shortcode) and then use the cred_save_data hook to get the field value from the global $_POST object and update the post meta yourself.
I followed your suggestions and it works. can you confirm if i did everything the right way, would appreciate that!
1- added following code with my form ID
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==12345)
{
if (isset($_POST['wpcf-winner-1']))
{
// add it to saved post meta
add_post_meta($post_id, 'wpcf-winner-1', $_POST['wpcf-winner-1'], true);
}
}
}
I am having an issue with the "EDIT" form. It doesn't save the values of the custom Radio Buttons!
I have added the ID of the edit form to the function. but this isn't working unless i add the original input of cred form.
the create post form work as expected, this issue show up only when editing the post
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data){
$ids = array("12345","67890");
// if a specific form
if (in_array($form_data['id'], $ids) ){
if (isset($_POST['wpcf-winner-1']))
{
// add it to saved post meta
add_post_meta($post_id, 'wpcf-winner-1', $_POST['wpcf-winner-1'], true);
}
if (isset($_POST['wpcf-winner-2']))
{
// add it to saved post meta
add_post_meta($post_id, 'wpcf-winner-2', $_POST['wpcf-winner-2'], true);
}
}
}
The function add_post_meta will only add the custom field where it doesn't already exist, it won't overwrite an existing value where you are editing a post.
You would need to change the add_post_meta calls to the following format to work both to add or update a custom field: