This following code snippet will make you better understand how the "cred_save_data" hook works.
Suppose that you have a Toolset form with ID "123" with a field with slugs "field-slug-1" and "field-slug-2". And you'd like to use the first field's value for the post title and the second one for the post's slug.
In this case, the code that you'll add in your active theme's "functions.php" file would be:
add_action('cred_save_data','custom_title_slug_func',15,2);
function custom_title_slug_func($post_id, $form_data) {
if ($form_data['id']==123) {
// get the value of fields
$field_1 = $_POST['wpcf-field-slug-1'];
$field_2 = $_POST['wpcf-field-slug-2'];
// set the values of fields in title and slug
$title = $field_1;
$slug = $field_2;
$my_post_data = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => sanitize_title($slug),
);
// Update the post into the database
wp_update_post( $my_post_data );
}
}
Feel free to adjust this snippet to match your website's form and custom field values, as needed.
For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/
Sorry to learn that the suggested code example doesn't work.
For further investigation into this, it would help if you could share the clone or snapshot of your website.
(it can be from this website or from another test website where the issue is reproducible)
If you already know how Duplicator works, you can skip the instruction video and just send me the installer file and the zipped package you downloaded.
Duplicator Instructions: hidden link
( note: I'll need both files and you'll probably want to use DropBox, Google Drive, or similar services, as the snapshot file will be quite big )
IMPORTANT: Remember to create or keep an admin account for me before creating the snapshot, or I won’t be able to log in. You may delete the new admin account once the snapshot has been built.
I will set your next answer as private so you can provide me the information securely.
regards,
Waqar
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.