Skip Navigation

[Resolved] 3 times the same cred save data function, but only the 2 first work !

This thread is resolved. Here is a description of the problem and solution.

Problem: I have 3 cred_save_data hooks that are used to update a custom field, but they do not seem to be working as expected.

Solution: Check to be sure the update_post_meta call is operating correctly. In this case, the 4th parameter was set as "true", which was causing problems with the update process.

Relevant Documentation: https://codex.wordpress.org/Function_Reference/update_post_meta

This support ticket is created 7 years, 3 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 2 replies, has 2 voices.

Last updated by romanB-3 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#555633

Hello,

I have 3 CRED forms, the first one creates the post, and the 2 other edit the post.

On each CRED form submission, I need to update the "status" of the post, which is a value between 0 to 6.

The first form and function update the custom field from "" to "1" ;
The second form and function update the custom field from "1" to "2" ;
But the third form and function don't update the custom field ! It stays "1" !!

The 3 functions are exactly the same :

add_action('cred_save_data', 'sauver_etat_commande_niv1',10,2);
function sauver_etat_commande_niv1($post_id, $form_data)
{if ($form_data['id']==197) {
	error_log($form_data['id'] . $post_id . 'wpcf-etat-de-la-demande' . '1');
	update_post_meta($post_id, 'wpcf-etat-de-la-demande', '1', true);}
}

add_action('cred_save_data', 'sauver_etat_commande_niv2',10,2);
function sauver_etat_commande_niv2($post_id, $form_data)
{if ($form_data['id']==266) {
	error_log($form_data['id'] . $post_id . 'wpcf-etat-de-la-demande' . '2');
	update_post_meta($post_id, 'wpcf-etat-de-la-demande', '2', true);}
}

add_action('cred_save_data', 'sauver_etat_commande_niv3',10,2);
function sauver_etat_commande_niv3($post_id, $form_data)
{if ($form_data['id']==291) {
	error_log($form_data['id'] . $post_id . 'wpcf-etat-de-la-demande' . '3');
	update_post_meta($post_id, 'wpcf-etat-de-la-demande', '3', true);}
}

Is there some kind of limitation with usage of cred save data ? Or what am I missing here ?!

Thank you.

#555699

Hi, first I would try to remove the 4th parameter, 'true', from each of your update_post_meta calls.

update_post_meta($post_id, 'wpcf-etat-de-la-demande', '1');}
...
update_post_meta($post_id, 'wpcf-etat-de-la-demande', '2');}
...
update_post_meta($post_id, 'wpcf-etat-de-la-demande', '3');}

From the docs at WordPress:
$prev_value
(mixed) (optional) The old value of the custom field you wish to change.

I don't think you should include "true" here. If this doesn't resolve the problem, please copy + paste the latest contents of your error log file here.

#555713

Fast and right into it. Great support. Thank you.