Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Multiple CPT posts from one gravity form submission

         

daftpunk3186

3:58 pm on Jun 6, 2015 (gmt 0)

10+ Year Member



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?

King of Bling

4:06 pm on Jun 6, 2015 (gmt 0)

10+ Year Member



If you are a PRO member of GF, try their Support. They are very helpful...!

daftpunk3186

4:16 pm on Jun 7, 2015 (gmt 0)

10+ Year Member



I am indeed, thankfully, however their forums are now offline. They've switched to a completely ticket-based system. I've submitted a ticket, so we'll see.. thanks for the suggestion though.