Skip Navigation

[Closed] Save CRED generic field value to database

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.

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Shane 5 years, 6 months ago.

Assigned support staff: 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.