You can use a script like the following in WP Console:
<?php
$args = [
'post_type' => 'dealers', // Replace with your post type
'posts_per_page' => -1,
'fields' => 'ids',
];
$posts = get_posts($args);
// replace with your ACF field keys and names
$fields_to_update = [
'field_658f34acfa8b1' => 'dealer_type',
'field_63e2523c7b2a8' => 'netsuite_id',
'field_63bc663415a82' => 'phone',
'field_63e16cc724134' => 'fax',
'field_63bc664f15a83' => 'website',
'field_63e252187b2a7' => 'website_domain',
'field_63bc67275b5ea' => 'open_hours',
'field_63bc7f1f02a3b' => 'location',
];
$acf_cpt = new Acf_ct_register_hooks();
$_POST['_acf_changed'] = "1";
foreach ($posts as $post_id) {
$_POST['acf'] = [];
foreach ($fields_to_update as $field_key => $field_name) {
$field_value = get_field($field_name, $post_id);
if ($field_value !== false) {
$_POST['acf'][$field_key] = $field_value;
}
}
// Call the function to handle saving the post
$acf_cpt->acf_ct_handle_save_post($post_id);
// Output for confirmation
echo "Processed post ID: {$post_id}\n";
}
You can find the field keys for your scenario by enabling ‘key’ under ‘Screen elements’ in the field group edit screen.
-
This reply was modified 10 months, 3 weeks ago by Kevin Shenk.