Home › Forums › Backend Issues (wp-admin) › Issue with update_field Not Storing Data in Custom Post Type › Reply To: Issue with update_field Not Storing Data in Custom Post Type
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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.