可以最后,我终于成功了。下面是完整的工作代码。
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\');
}
}