admin管理员组文章数量:1130349
I'm attempting to have Gravity Forms create two post types in one form, based on data in the form.
The two post type slugs are teardown and engine, and it's successful in creating both posts, but none of the custom fields form data is passing to the database. I'm left with an empty post. However, I am getting notifications from GF submission notifications showing the form data in the email. For some reason it isn't passing through to the CPT post when I view in the admin panel.
Why is the form data not populating the custom fields? It seems like there is a disconnect with the $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 );
}
}
}
Credit: This code is based on a super helpful response from GhostToast
I'm attempting to have Gravity Forms create two post types in one form, based on data in the form.
The two post type slugs are teardown and engine, and it's successful in creating both posts, but none of the custom fields form data is passing to the database. I'm left with an empty post. However, I am getting notifications from GF submission notifications showing the form data in the email. For some reason it isn't passing through to the CPT post when I view in the admin panel.
Why is the form data not populating the custom fields? It seems like there is a disconnect with the $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 );
}
}
}
Credit: This code is based on a super helpful response from GhostToast
Share Improve this question edited Jun 5, 2015 at 20:23 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Jun 5, 2015 at 19:59 CA_CA_ 131 silver badge7 bronze badges 2- perhaps $post_id is not greater than 0? If the post is created but the custom fields are not added, the problem might be with the foreach loop or the if wrapping it. – gdaniel Commented Jun 5, 2015 at 21:45
- But shouldn't that function return an integer if the function successfully created a post? – CA_ Commented Jun 6, 2015 at 2:09
1 Answer
Reset to default 0I know this is an old post, but a Google search brought me here.
Where are you getting $user_ID and your array $entry ? They are not defined anywhere in your functions.
Where does $entry come from? I know HOW to get the user_ID, but you not doing so anywhere in this code.
I'm attempting to have Gravity Forms create two post types in one form, based on data in the form.
The two post type slugs are teardown and engine, and it's successful in creating both posts, but none of the custom fields form data is passing to the database. I'm left with an empty post. However, I am getting notifications from GF submission notifications showing the form data in the email. For some reason it isn't passing through to the CPT post when I view in the admin panel.
Why is the form data not populating the custom fields? It seems like there is a disconnect with the $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 );
}
}
}
Credit: This code is based on a super helpful response from GhostToast
I'm attempting to have Gravity Forms create two post types in one form, based on data in the form.
The two post type slugs are teardown and engine, and it's successful in creating both posts, but none of the custom fields form data is passing to the database. I'm left with an empty post. However, I am getting notifications from GF submission notifications showing the form data in the email. For some reason it isn't passing through to the CPT post when I view in the admin panel.
Why is the form data not populating the custom fields? It seems like there is a disconnect with the $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 );
}
}
}
Credit: This code is based on a super helpful response from GhostToast
Share Improve this question edited Jun 5, 2015 at 20:23 Gabriel 2,24810 gold badges22 silver badges24 bronze badges asked Jun 5, 2015 at 19:59 CA_CA_ 131 silver badge7 bronze badges 2- perhaps $post_id is not greater than 0? If the post is created but the custom fields are not added, the problem might be with the foreach loop or the if wrapping it. – gdaniel Commented Jun 5, 2015 at 21:45
- But shouldn't that function return an integer if the function successfully created a post? – CA_ Commented Jun 6, 2015 at 2:09
1 Answer
Reset to default 0I know this is an old post, but a Google search brought me here.
Where are you getting $user_ID and your array $entry ? They are not defined anywhere in your functions.
Where does $entry come from? I know HOW to get the user_ID, but you not doing so anywhere in this code.
本文标签: custom fieldCreating multiple CPT posts from one Gravity form
版权声明:本文标题:custom field - Creating multiple CPT posts from one Gravity form 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749231753a2336604.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论