I need the "auteur" title post to be populated by the the "auteur-name" custom field. I guess I need something similar to this, but I am not using the CRED plugin. Thanks
add_action('cred_save_data', 'custom_title',10,2);
function custom_title($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==319)
{
// Update post 37
$title = $_POST['wpcf-name-auteur'];
add_filter( 'wp_insert_post_data' , 'set_auto_title_auteur_fn' , '99', 2 );
function set_auto_title_auteur_fn( $data, $postarr )
{
if( $data['post_type'] == 'auteur' ) {
// get the value from the field
$field_value = $postarr['wpcf']['name-auteur'];
//Updates the post title to the new value
$data['post_title'] = $field_value ;
}
return $data; // Returns the modified data.
}
Note: Please update "auteur" and "name-auteur" to match the actual post's slug and the custom field's slug respectively.
Thanks I uploaded the code in function.php but with the code implemented all the necessary fileds are not showing when adding a new "Auteur" - see attached images with and without the code.
Thanks for sharing the update and the screenshots.
To avoid this issue (which appears only when adding a new post and not editing existing ones), you can slightly update line# 4 in the code snippet, I shared earlier.