Skip Navigation

[Resolved] Issue with function

This support ticket is created 4 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by larryL 4 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1693217

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));
}
}

#1693489

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.

#1697033

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));
}
}

#1704477

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.

#1709029

Hey Christian how can I send a private message?

#1709169

I can activate private fields for your next reply. You may add filler dummy data to any required fields that do not apply.

#1713363

Private please...

#1713741

Private fields enabled here

#1725305

My issue is resolved now. Thank you!