[Resolved] Adding a repeating field entry whilst preserving existing entries

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Related documentation: CRED API

This topic contains 4 replies, has 3 voices, and was last updated by  Nigel 11 months, 1 week ago. The support staff assigned to this topic is Nigel.

Viewing 5 posts - 1 through 5 (of 5 total)

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:

[cred_generic_field field='caregiver-comments-application-add' type='textarea' class='' urlparam='']

I have a function that looks like this:

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);

I borrowed the code above from here: https://toolset.com/documentation/programmer-reference/cred-api/

Thanks in advance 🙂


Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

So - the code you added to your current theme's functions.php file do not work?


Hi Minesh, it definitely doesn't work 🙁


Forum moderator

Supporter languages: English (English )

Supporter Timezone: Asia/Kolkata (GMT+05:30)

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.


Forum moderator

Supporter languages: English (English ) Spanish (Español )

Supporter Timezone: Europe/London (GMT+01:00)

Hi Greig

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?

Viewing 5 posts - 1 through 5 (of 5 total)