I am trying to:
I have a front end form that creates a post in a custom post type all created by toolset. The field that is not working on the post reference field to another post which only returns post id in the db. it was working fine in the past but suddenly, i am seeing this weird issue.
When i enter the form from the front end to update custom field reference and hit submit the database is not updated with that custom field. but i am able to see the field in the wp-admin side.
I am trying to access that field via php by $recievingcounty = get_post_meta( $currentpostid );
var_dump($recievingcounty);
and getting null.
When i go back in the wp admin, the field is populated properly. Now if i update the post by hitting update in the backend the database gets updated and everything starts to work again.
I have the field on the front end, if you read thru my description properly and look at thee images step by step you can see what issue i am having. I have the field working but there seems to be a bug that from front end is not updating database with the custom field.
Upon doing further research on this issue. I found out that post reference custom field is not being saved in the post_meta table from the front end form. When i go in the admin panel and update the post only then post_meta table updates.
Ok - so what if you try to use the Forms hook cred_save_data to save the field value.
Please try to add following code to your current theme's functions.php file.
add_action('cred_save_data', 'func_update_post_reference_field',10,2);
function func_update_post_reference_field($post_id, $form_data){
// if a specific form
if ($form_data['id']==9999) {
update_post_meta($post_id, 'wpcf-receiving-countynew', $POST['wpcf-receiving-countynew']);
}
}
Where:
- Replace 9999 with your original form ID
If the above code does not help, please share problem URL where you added the form with access details so I can fix it for you.
I have set the next reply to private which means only you and I have access to it.