Support

Account

Home Forums Front-end Issues ACF Front-end form not saving data

Unread

ACF Front-end form not saving data

  • Hi!

    I have a taxonomy with a custom post type and created a page, where I entered the following code to give the opportunity creating new posts of this post type.

    In my xxPAGE.php:

    
    <?php 
    
    			$args = array(
    				'post_id' => 'new',
    				'field_groups' => array( 13509 ),
    
    			);
    
    			acf_form( $args ); 
    
    			?>
    
    

    On top I have of course
    <?php acf_form_head();
    get_header(); ?>

    In my FUNCTIONS.php there is the following code:

    
    function my_pre_save_post( $post_id )
    {
        if( $post_id != 'new' )
        {
            return $post_id;
        }
    
        $post = array(
            'post_status'  => 'publish' ,
            'post_title'  => 'Testunternehmen' ,
            'post_type'  => 'unternehmensprofile' ,
        );  
    
        $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' );
    

    The form is displayed and when submitted, the page loads correctly, the URL adds “updated=true” and there is the system message “Created”..

    But there is no post even in the posts nor the taxonomy.

    Would appreciate help!

    Thank you!

Viewing 1 post (of 1 total)

The topic ‘ACF Front-end form not saving data’ is closed to new replies.