Home › Forums › ACF PRO › Save/update field of custom field with function › Reply To: Save/update field of custom field with function
If all you are trying to do is update a parent post when the post is saved then something like this should do it. Please note that this may not be exactly the code and it’s just an outline.
add_action('acf/save_post', 'some_function_name_here', 20);
function some_function_name_here($post_id) {
// get the value from the saved post that you want to use
$value = get_field('field_name', $post_id);
if (!$value) {
// no value, no need to continue
return;
}
$parent = wp_get_post_parent_id($post_id);
if (!$parent) {
// not parent post, bail
return;
}
// use update_field to update the value on the parent post
update_field('field-name-on-parent-post', $parent, $value);
}
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.