Skip Navigation

[Closed] Save CRED generic field value to database

This support ticket is created 8 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Shane 8 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#341888

Hi,

According to the document

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred-generic-field

'Please note that if the value of Generic Field is to be saved in the Database, “persist” option must be set to “1”.'

Do that mean as long as 'persist' option is set to 1, the value will be automatically stored to database as part of the post that the CRED form is creating? A little hard to understand, since I assume filter hook is required to save such generic field value to database.

#341931

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dejun,

Thank you for contacting our support forum.

If you were to use a generic field to populate a custom field already created in types then when you set the field to persist then it will automatically populate that custom field.

If the field does not exist then you will need to hook into CRED and manually do the binding.

Please let me know if this clears this up for you a bit.

Thanks,
Shane

#342085

Hi Shane,

It is still a little hard for me to understand.....since there is already a custom field there, why we bother to use generic field to populate it, instead of using post field?

BTW, do you have any example hook code of such case that I can start with?

Thanks a lot for your help.

Regards,
Derek

#342091

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dejun,

The generic field is useful if the website's creator wants to give users a fixed choice for e.g with taxonomy tags. Instead of allowing a user to choose their own tags, you can use a generic field to setup a predefined set of tags so a user can choose from.

Below is an example of a hook to manually populate a custom field.

add_action('cred_save_data', 'custom_function',10,2);
function custom_function($post_id, $form_data)
{
	// if a specific form
	if ($form_data['id']==33)
	 
	{
		$field= $_POST["my_generic_field"];


	 update_post_meta($post_id, 'custom_field', $field)		 
	}
}

The function above is a basic example on how to do a manual binding to a custom field.

Please let me know if this helps.
Thanks,
Shane

The topic ‘[Closed] Save CRED generic field value to database’ is closed to new replies.