• 1.
    // code in the template
  • 2.
     
  • 3.
    acf_form(array(
  • 4.
    	'post_id'		=> 'new_p',
  • 5.
    	'field_groups'       => array(866),
  • 6.
    	'updated_message' => 'Post Updated',
  • 7.
    	'new_p'		=> array(
  • 8.
    		'post_type'		=> 'recipe',
  • 9.
    		'post_status'		=> 'publish',
  • 10.
    	)
  • 11.
    ));
  • 12.
     
  • 13.
    // code in the functions.php
  • 14.
     
  • 15.
    add_filter('acf/pre_save_post' , 'ik_do_pre_save_post' );
  • 16.
    function ik_do_pre_save_post( $post_id ) {
  • 17.
     
  • 18.
     
  • 19.
    	if( $post_id != 'new_p' ) {
  • 20.
    		return $post_id;
  • 21.
    	}
  • 22.
     
  • 23.
    	$post = array(
  • 24.
    		'post_type'     => 'recipe', 
  • 25.
    		'post_status'   => 'publish', 
  • 26.
    		'post_title'    => wp_strip_all_tags($_POST['acf']['field_55a00fa6ba98f']),
  • 27.
    	);
  • 28.
     
  • 29.
    	$post_id = wp_insert_post( $post );
  • 30.
     
  • 31.
     
  • 32.
    	return $post_id;
  • 33.
     
  • 34.
    }
// code in the template acf_form(array( 'post_id' => 'new_p', 'field_groups' => array(866), 'updated_message' => 'Post Updated', 'new_p' => array( 'post_type' => 'recipe', 'post_status' => 'publish', ) )); // code in the functions.php add_filter('acf/pre_save_post' , 'ik_do_pre_save_post' ); function ik_do_pre_save_post( $post_id ) { if( $post_id != 'new_p' ) { return $post_id; } $post = array( 'post_type' => 'recipe', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags($_POST['acf']['field_55a00fa6ba98f']), ); $post_id = wp_insert_post( $post ); return $post_id; }

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter