Why would this not work:
//Force title for Add Record from VIN field.
add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {
$forms = array( 942,2101,937 );
if ( in_array($form_data['id'], $forms) ){
$vin = get_post_meta($post_id, 'wpcf-vin', true);
$post_title=$vin;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}
//Force title for Add Record from Call Code field.
add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {
$forms = array( 22067 );
if ( in_array($form_data['id'], $forms) ){
$vin = get_post_meta($post_id, 'wpcf-call-code', true);
$post_title=$call-code;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}
The first thing I can see is that you have two functions called build_post_title, which is illegal in PHP. You should rename the functions to use unique names, and update the corresponding add_action lines to point to the correct unique function names. Next, use $call_code as the variable name instead of $call-code. The hyphen is illegal in a variable name. Then check the code from the second function here - you probably need to change $vin to $call_code:
$forms = array( 22067 );
if ( in_array($form_data['id'], $forms) ){
$vin = get_post_meta($post_id, 'wpcf-call-code', true);
Beyond that, you'll need to add error log statements to determine how and why the code is breaking down.
Hey Christian! Did you mean to enable logging in wp-config?
I made the changes you suggested (I think?) and it still takes the site down.
//Force title for Add Record from VIN field.
add_action('cred_save_data', 'build_post_title_1', 10, 2);
function build_post_title_1($post_id, $form_data) {
$forms = array( 942,2101,937 );
if ( in_array($form_data['id'], $forms) ){
$vin = get_post_meta($post_id, 'wpcf-vin', true);
$post_title=$vin;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}
//Force title for Add Record from Call Code field.
add_action('cred_save_data', 'build_post_title_2', 10, 2);
function build_post_title_2($post_id, $form_data) {
$forms = array( 22067 );
$call_code in_array($form_data['id'], $forms) ){
$call_code = get_post_meta($post_id, 'wpcf-call-code', true);
$post_title=$call_code;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}
Typo here:
$forms = array( 22067 );
$call_code in_array($form_data['id'], $forms) ){
$call_code = get_post_meta($post_id, 'wpcf-call-code', true);
That should probably be:
$forms = array( 22067 );
if( in_array($form_data['id'], $forms) ){
$call_code = get_post_meta($post_id, 'wpcf-call-code', true);
Did you mean to enable logging in wp-config?
Yes that's right, if the code isn't working as expected once you make the change above, you'll need to enable logging so we can debug the problem. Let me know if that is the case, I can help.
Hey Christian how can I send a private message?
I can activate private fields for your next reply. You may add filler dummy data to any required fields that do not apply.
Private fields enabled here
My issue is resolved now. Thank you!