Multiple CPT created from one Gravity Form submission

  • Unknown's avatar

    Hello,

    I’m attempting to create a Gravity Form which will create a post of two post types, teardown and engine.

    I am successful in creating the actual posts from the form submission, however, none of the custom field data is being written to the database. I’m left with empty post, albeit correctly created by the form, but no form data. It seems to be a disconnect with $entry[] in the meta arrays. I’m receiving emails of form submission confirmations with field data, but nothing is populating in the posts when I view in Admin.

    Here’s my code below:

    add_action( 'gform_after_submission_1', 'after_submission', 10, 2 );
    function after_submission() {
        // TEARDOWN POST TYPE STARTS HERE
            $td_post_args = array(
            'comment_status' => 'closed',
            'ping_status' => 'closed',
            'post_author' => $user_ID,
            'post_title' => $entry[1],
            'post_status' => 'draft',
            'post_type' => 'teardown',
        );
        $post_id = wp_insert_post( $td_post_args );
    
        // TEARDOWN CPT META VALUES
        $td_meta_values = array(
            'wpcf-td-mfg' => $entry[2],
            'wpcf-td-model' => $entry[3],
            'wpcf-td-msn' => $entry[4],
            'wpcf-td-location' => $entry[7],
            'wpcf-td-tail-number' => $entry[5],
            'wpcf-td-last-operator' => $entry[6],
        );
        if ( $post_id > 0 ) {
            foreach ( $td_meta_values as $key => $value ) {
                update_post_meta( $post_id, $key, $value );
            }
        }
    
        // ENGINE POST TYPE STARTS HERE
        $engine_post_args = array(
            'comment_status' => 'closed',
            'ping_status' => 'closed',
            'post_author' => $user_ID,
            'post_title' => $entry[1],
            'post_status' => 'draft',
            'post_type' => 'engine',
        );
        $post_id = wp_insert_post( $engine_post_args );
        $engine_meta_values = array(
            'wpcf-td-engine-model' => $entry[11],
            'wpcf-td-engine-pn' => $entry[13],
            'wpcf-td-engine-qty' => $entry[14],
        );
        if ( $post_id > 0 ) {
            foreach ( $engine_meta_values as $key => $value ) {
                update_post_meta( $post_id, $key, $value );
            }
        }
    }

    I’m also confused with this portion, as this check should be returning an integer if the creation of the posts is successful (which it has been).

    if ( $post_id > 0 ) {
            foreach ( $td_meta_values as $key => $value ) {
                update_post_meta( $post_id, $key, $value );
            }

    Why are the custom fields not being populated by the form data?

  • Unknown's avatar

    Hi, you are in the wrong forum.
    This forum is only for blogs/sites hosted by WordPress.com
    WordPress.COM and WordPress.ORG are completely separate and different http://support.wordpress.com/com-vs-org/

    And you should ask in the WordPress.org forum.
    http://wordpress.org/support/

  • The topic ‘Multiple CPT created from one Gravity Form submission’ is closed to new replies.