Support

Account

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);
    }