Hi John,
Thanks for your reply.
I am using field keys for the update, and they update the database with the correct values, but I can’t get the values to link to the custom post type and show in Admin.
Here’s a short version of what I’ve been doing. The whole script duplicates a number of pages and should add their respective field values.
$new_page_id = wp_insert_post([
'post_title' => $new_title,
'post_name' => $new_slug,
'post_content' => $original_page->post_content,
'post_status' => 'publish',
'post_type' => 'page',
'post_parent' => $parent_id,
]);
if ($new_page_id) {
update_acf_field("field_652e5e0552a46", true, $new_page_id, "Is Duplicate");
update_acf_field("field_652e5e2e52a47", $original_page_id, $new_page_id, "Page Id");
}
function update_acf_field($field_key, $value, $new_page_id, $description)
{
$updated = update_field($field_key, $value, $new_page_id);
error_log('-- SET ' . $value. ' - Updated: ' . ($updated ? "true" : "false"));
}
I’m not sure how to proceed, or whether my approach is valid.
Any further help or guidance would be greatly appreciated.
Thank you!
Paul