Support

Account

Home Forums General Issues Using acf_form – add post title… Reply To: Using acf_form – add post title…

  • Worked this out. @greenhoe hope this helps.

    // Create the frontend form
    function my_pre_save_post( $post_id ) {
    	if ( $post_id != 'new' ) {
    		return $post_id;
        }
        $post = array(
            'post_status' => 'draft',
            'post_title' => $_POST['fields']['field_5344021b6851b'],
            'post_type' => 'events'
        );  
        $post_id = wp_insert_post($post); 
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
        return $post_id;
    }
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );

    Now ACF allows a $_POST variable to be used for the title but does not really state how to use it. We create a title field in ACF and then used the field name that was automatically generated from ACF. So, as above:

    'post_title' => $_POST['fields']['field_5344021b6851b'],

    field_5344021b6851b is the name of my title field I created.

    Hope this helps. Worked for me. Let me know if you have any problems.
    -R