add_action('cred_save_data', 'increase_custom_value',10,2);
function increase_custom_value($post_id, $form_data)
{
//NOTE: Set your form ID instead of 12
if ($form_data['id']==2775)
{
//Get count field from database and add 1
$count = intval(get_post_meta( $post_id, 'wpcf-count', TRUE )) +1;
//Update count field
update_post_meta($post_id, 'wpcf-count', $count);
}
}
With a CRED form id=2775. I have ajax DISabled. The field COUNT is numeric.
I have disabled all plugins but Toolset: CRED Types Views MAPS
Using the generic theme that comes with WordPress 2017
I just want every new record to get a value in "COUNT" that is the value of COUNT of the last record + 1.
That isn't happen though, the field keeps getting updated with the same number, "1".
The code I shared will work from start - if you need existing counts - it needs to be adjusted.
I need access details and where you want to display the count?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
I've find the option key "cpt_issues_count" in database table options and adjusted the current number of counts value and then I've added the new record and I see the code is working fine.
I think there's a miscommunication of what I am trying to achieve.
I want to be able to update the record with a unique number, then display this unique number.
I have a field named "count" for this purpose. On the "add issue" form SAVE, I want that number to be assigned, or updated.
It should display in this field in the back end: hidden link
It should display when you display the record itself: hidden link
Your test left the field "count" empty, instead of filling it with a unique ID.