'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.
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.
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?
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.