我试图让Gravity表单根据表单中的数据在一个表单中创建两种帖子类型。
两个立柱式缓动阀为teardown
和engine
, 它成功地创建了两个帖子,但没有一个自定义字段表单数据传递到数据库。我留下了一个空帖子。然而,我收到了来自GF提交通知的通知,其中显示了电子邮件中的表单数据。由于某些原因,当我在管理面板中查看时,它没有传递到CPT帖子。
为什么表单数据没有填充自定义字段?似乎与$entry[]
?
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 );
}
}
}
信用:此代码基于GhostToast的一个非常有用的响应