Support

Account

Home Forums Front-end Issues Front end post creation and update on same page

Solved

Front end post creation and update on same page

  • Hi,
    I have a page where you a few tabs, in one tab you can create a CPT with the ACF frontend forms, and in another tab you should be able to update the current post.

    The CPT creation works fine and as expected, however the existing post to update isnt working.

    It pulls in the correct data on load, but if you update the information and click save, nothing saves, the page seems to just refresh.

    I have this in my header:

    <?php function my_pre_save_post( $post_id ) {
          // Create a new post
          $post = array(
          	'post_status'  => 'publish' ,
          	'post_type'		=> 'acquisitions',
       		//Use the ACF fields to create the title or any other field.
          	'post_title'  => 'Acquisition' . ' ' . current_time( 'd/m/Y H:i:s', $gmt = 0 ),
          );  
    
          // insert the post
          $post_id = wp_insert_post( $post );
       	 // return the new ID
       	 return $post_id;
        }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 1, 1 ); ?>
    
    <?php acf_form_head(); ?>
    
    <?php get_header(); ?>

    And the form to update the current post is:
    <?php acf_form(); ?>

    Any ideas why this isnt updating and working as expected?

    Thanks,
    Mike

  • I suspect that you’re creating a new post each time rather than updating anything, but that just a guess. I say this because your pre_save_post filter does no checking to see if the post_id is for a new post or an existing post. Your filter should only be run when the post_id is “new” or whatever value you’re using for the acf form for the new post creation see https://www.advancedcustomfields.com/resources/acf-pre_save_post/ and https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.