acf form create new post and update acf fields code example

Example: acf form update post

<?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(); ?>

Tags:

Html Example