Support

Account

Home Forums Front-end Issues Use only one submit button with two acf_form saving to specific post ids Reply To: Use only one submit button with two acf_form saving to specific post ids

  • This could potentially be done, but the process would be painful.

    First you would use the user ID as the id for the form and you would include all of the field and/or groups for the user and the post you want in the form using the acf form settings that let you do this.

    Second you would need to supply your own hidden field for $associacao->ID or you would need to look this up when the the post is saved.

    Next you would need to create an acf/save_post action with a priority of <10 so that it runs before ACF.

    This action should run when the user is being updated if (substr($post_id, 0, 5) == 'user_))`

    You would then need to loop over $_POST[‘acf’], update the fields for the post and then remove them from the array.

    
    if (!emtpy($_POST['acf'])) {
      foreach ($_POST['acf'] as $field_key => $value) {
        
        // you'll need to supply your own logic in this if statement
        if (/* This field key belongs to the post */) {
          // update the post value
          update_field($field_key, $value, $associated_id);
          // remove this field from the array so that ACF does not add it to user
          unset($_POST['acf][$field_key];
        }
    
        
      }
    }