Hello i 'm using cred to enter custom post content.
I removed from cred form submitting of post title because i don't need the title.
When i compile the cred form post title is autogenerating like: CRED Auto Draft 372bce54fa46f7c17fa3f8d8027cefe1
I have:
custom field1=nome
custom field2=cognome
I would want the post name = nome+cognome
My request is similar to this:
https://toolset.com/forums/topic/automatically-generate-custom-post-title-based-on-custom-fields/
I tried to add to function.php this code (don't seem to working):
if ($form_data["id"]==36)
{
if (isset($_POST["nome"]) && isset($_POST["cognome"]) ){
$name = $_POST["nome"]." ".$_POST["cognome"];
// Update the post into the database
$my_post = array(
'ID' => $post_id,
'post_title' => $name
);
wp_update_post( $my_post );
}
}
}
My cred ID is 36 like in the code
It's possible to achieve this?
Thanks
Ok i managed the solution looking to other threads on this forum.
I post the solution here to help other users:
Auto-title custom post type like sum of custom fields (in my case nome - cognome)
ADD TO FUNCION.PHP
function my_save_data_action($post_id, $form_data){
// Change your CRED Form "ID" accordingly below
//Declare the content of your variables, change "your_custom_field_slug" accordingly
$nome = get_post_meta( $post_id, 'wpcf-nome', true );
$cognome = get_post_meta( $post_id, 'wpcf-cognome', true );
//collect data and define new title
$my_post = array(
'ID' => $post_id,
'post_title' => $nome . '-' . $cognome,
'post_name' => $nome . '-' . $cognome,
);
// Update the post into the database
wp_update_post( $my_post );
}
add_action('cred_save_data', 'my_save_data_action',10,2);
Don't think the code is perfect but seem to work good, post link too.