Support

Account

Home Forums Front-end Issues Using acf_form to create a new post Reply To: Using acf_form to create a new post

  • i have the same problem here.

    i created a custom post type “datensatz” and also used the scripts from this site: http://www.advancedcustomfields.com/resources/tutorials/using-acf_form-to-create-a-new-post/

    i created a page with a template like this:

    <?php acf_form_head();
    get_header(); ?>
     
    	<div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    		
    			<?php /* The loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
     
    				<?php acf_form(array(
    					'post_id'	=> 'new',
    					'submit_value'	=> 'Neuen Datensatz erstellen'
    				)); ?>
     
    			<?php endwhile; ?>
    			 
    		</div><!-- #content -->
    	</div><!-- #primary -->
     
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    and added the following code in my functions.php:

    function my_pre_save_post( $post_id ) {
     
        // check if this is to be a new post
        if( $post_id != 'new' )
        {
            return $post_id;
        }
     
        // Create a new post
        $post = array(
            'post_status'  => 'draft',
            'post_title'  => 'Test',
            'post_type'  => 'datensatz',
        );
     
        // insert the post
        $post_id = wp_insert_post( $post );
     
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
     
        // return the new ID
        return $post_id;
    }
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );

    on the page in the frontend just the submit button with my custom text shows up, but the form is missing.

    i would really appreciate your support. thank you!