Tell us what you are trying to do? We are trying to insert a function to autocomplete the cpt title from two custom fields (name and surname)
Is there any documentation that you are following? Yes: https://toolset.com/forums/topic/cred-form-title-auto-fill/ - this is a topic already opened but the solution does not work for us.
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
You need to use the cred_save_data hook to modify the title after the post has been submitted.
Here is the simplest example of some code to do what you asked:
/**
* Auto-set post title
*/
add_action( 'cred_save_data', 'tssupp_form_submit', 10, 2 );
function tssupp_form_submit( $post_id, $form_data ){
if ( in_array( $form_data['id'], array( 123 ) ) ) {
$first = get_post_meta( $post_id, 'wpcf-first-name', true );
$last = get_post_meta( $post_id, 'wpcf-last-name', true );
wp_update_post( array(
'ID' => $post_id,
'post_title' => $first . ' ' . $last
)
);
}
}
You would need to edit the ID of the Form (123 in the sample code), and you need to edit the keys of the fields which store the first and last names ('wpcf-first-name' and 'wpcf-last-name'; note the 'wpcf-' prefixes for Types fields).
My issue is resolved now. Thank you!