@@ -32,6 +32,17 @@ function wplf_ajax_submit_handler() {
3232 // the title is the value of whatever the first field was in the form
3333 $ title_format = get_post_meta ( $ form ->ID , '_wplf_title_format ' , true );
3434
35+ // create submission post
36+ $ post_id = wp_insert_post ( array (
37+ 'post_title ' => '' ,
38+ 'post_status ' => 'publish ' ,
39+ 'post_type ' => 'wplf-submission ' ,
40+ ) );
41+
42+ // exposes $post_id in $_POST to be able to use in the title
43+ // hacky, but uses less memory than a copy of $_POST
44+ $ _POST ['submission-id ' ] = $ post_id ;
45+
3546 // substitute the %..% tags with field values
3647 $ post_title = $ title_format ;
3748
@@ -44,12 +55,14 @@ function wplf_ajax_submit_handler() {
4455 $ post_title = preg_replace ( '/%.+?%/ ' , $ replace , $ post_title , 1 );
4556 }
4657
47- // create submission post
48- $ post_id = wp_insert_post ( array (
49- 'post_title ' => $ post_title ,
50- 'post_status ' => 'publish ' ,
51- 'post_type ' => 'wplf-submission ' ,
52- ) );
58+ // save the title
59+ wp_update_post ( [
60+ 'ID ' => $ post_id ,
61+ 'post_title ' => $ post_title ,
62+ ] );
63+
64+ // don't save the post id in meta
65+ unset( $ _POST ['submission-id ' ] );
5366
5467 // add submission data as meta values
5568 foreach ( $ _POST as $ key => $ value ) {
0 commit comments