My CPT is an application. The user submits the application which is then processed. The processing stage may take some time, during which the user may want to add further comments to that record. What I don't want is for the user to edit or delete the previous comments they have made, hence a normal implementation of a CRED form field is no good here.
The slug for this field is "caregiver-comments-application"
I have a form with which the user can edit their application. I have used a [types field=] to display previous comments. I have then created a generic field as follows:
add_action('cred_save_data', 'add_caregiver_comment_to_application',10,2);
function add_caregiver_comment_to_application($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==6973)
{
if (isset($_POST['caregiver-comments-application-add']))
{
// add it to saved post meta
add_post_meta($post_id, '__caregiver-comments-application', $_POST['caregiver-comments-application-add'], true);
}
}
}
Could you please share problem URL and share one test case example what you want to hide and what you want to show and where?
Do you mean in admin section you do not want to allow to delete repeating field entry or on frontend?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Minesh is absent today so let me see if I can help you.
Looking at your code sample I can see two problems with your add_post_meta call.
1. The key for Types custom fields is the field slug with the prefix "wpcf-", so in your case that should be "wpcf-caregiver-comments-application"
2. The final argument is the $unique parameter and is set to 'true'. From the documentation: "When set to true, the custom field will not be added if the given key already exists among custom fields of the specified post." (https://codex.wordpress.org/Function_Reference/add_post_meta.) This should be set to false.
Can you try changing the above and see if it works?
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.