在您提到的示例链接中,它假设您使用的是重力表单中内置的后期生成功能。我想,如果您试图在每个表单提交中创建多个post对象,您可能会想绕过这个问题。在gform_after_submission
胡克,我会这样做。。。
// add the new post EVENT
$event_post_args = array(
\'comment_status\' => \'closed\', // or open
\'ping_status\' => \'closed\',
\'post_author\' => 1, // this represents admin by default.
// might need to pull user info if is real user
\'post_title\' => $entry[1] . \' - \' . $entry[2], // note i have no clue
// what you want here
\'post_status\' => \'publish\',
\'post_type\' => \'event\',
);
// this returns an integer on success, 0 on failure - creates post!
$post_id = wp_insert_post( $event_post_args );
// add more meta values if you need
$event_meta_values = array(
\'event_address\' => $entry[3],
\'event_phone\' => $entry[4],
\'event_something\' => $entry[5],
);
// as long as wp_insert_post didnt fail...
if($post_id > 0){
foreach($event_meta_values as $key => $value) {
// add our post meta
update_post_meta($post_id, $key, $value);
}
}
// now we just do the same kind of thing for other Post Type
$club_post_args = array(
...
...
\'post_title\' => $entry[6],
);
// etc.
记住你的
gform_after_submission
钩子,可能应该为一种特定的形式专门构建。可以在挂钩上添加下划线和表单ID来完成以下操作:
gform_after_submission_7
, 例如
您可能还需要在代码中使用一些条件,以确保这些值在尝试对其进行post或post meta之前不为空。
如果你需要更多的解释,请告诉我。