Support

Account

Home Forums General Issues update_field on a relationship field Reply To: update_field on a relationship field

  • I’m not sure where I’m going wrong but I can’t seem to get it to work for me;

    add_action("gform_after_submission_2", "acf_post_submission", 10, 2);
    function acf_post_submission ($entry, $form) {
        //if the Advanced Post Creation add-on is used, more than one post may be created for a form submission
        //the post ids are stored as an array in the entry meta
        $created_posts = gform_get_meta( $entry['id'], 'gravityformsadvancedpostcreation_post_id' );
        foreach ( $created_posts as $post ) {
            $post_id = $post['post_id'];
            // Do your stuff here.
            echo "<br />Post ID: " . $post_id;
            $values = rgar( $entry, '11' );
            echo "<br />Billing Entity: " . $values;
            // get current value
            $value = get_field('billing_entity', $post_id, false);
            // add new id to the array
            $value[] = $values;
            // update the field
            update_field('field_66b0d39eed031', $value, $post_id);
        }
    }
    

    The relationship field doesn’t update.