You’ve got the right idea but you are using some of the functions and function arguments incorrectly.
// get all post IDs
$post_ids = get_posts(
array(
'post_type' => 'post',
'post_status' => 'publish',
'numberposts' => -1, // get all posts.
'fields' => 'ids', // Only get post IDs
)
);
// info: custom field 'actor' = 'Tom Hanks'
$customfield_value = get_post_meta($post_ids, 'actor', true);
// change the custom field values to slug format: 'Tom Hanks' > 'tom-hanks'
$customfield_value = sanitize_title_with_dashes($customfield_value);
// Update all posts
foreach ($post_ids as $id) {
$post = array(
'ID' => $id, // select all posts - not sure if that works with the array from $post_ids.
'tax_input' => array(
'actor' => array(
$customfield_value
)
)
);
// Update the post into the database
wp_update_post( $post );
// delete the old post meta after we moved it to the taxononmy
delete_post_meta($id, 'actor');
}
That is untested. Do not run that on a production database without first testing it on a copy first. Be very, very careful especially with deleting the post meta. That is not reversible.