1

I used the code found here. However, that does not update the title field until you open the post and hit Update button both via the back and front-end. I tried changing "save-post" hook with "edit_post", "publish_artist" and "wp_insert_post_data" but still get the same result. Below is the code I used upon using "wp_insert_post_data" hook.

add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 ); // Grabs the inserted post data so you can modify it.

function modify_post_title( $data )
{
  if($data['post_type'] == 'artist' && isset($_POST['artist_name'])) { // The custom field
    $ArtistName = $_POST['artist_name'];
    $data['post_title'] =  $ArtistName ; //Updates the post title to your new title.
  }
  return $data; // Returns the modified data.
}

1 Answer 1

2

Okay! Finally, I was able to make it work. Below is the complete working code.

add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 ); // Grabs the inserted post data so you can modify it.

function modify_post_title( $data )
{
  if($data['post_type'] == 'artist' && isset($_POST['acf']['field_573676a95d920'])) { // If the actual field name of the rating date is different, you'll have to update this.
    $ArtistName = $_POST['acf']['field_573676a95d920'];
    $data['post_title'] =  $ArtistName ; //Updates the post title to your new title.
  }
  return $data; // Returns the modified data.
}

//Save ACF field as post_title for front-end
add_action('acf/save_post', 'change_artist_title_frontend');

function change_artist_title_frontend($post_id) {
    global $_POST;
    if('artist'== get_post_type())
    {
        $post_custom_title = $_POST['acf']['field_573676a95d920'];
        $my_post = array();
                $my_post['ID'] = $post_id;
                $my_post['post_title'] = $post_custom_title;
remove_action('acf/save_post', 'change_artist_title_frontend');
                    wp_update_post( $my_post );
add_action('acf/save_post', 'change_artist_title_frontend');
    } 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.