Support

Account

Home Forums ACF PRO Front end form,how to change post_title and post_content properties Reply To: Front end form,how to change post_title and post_content properties

  • Hi @novelgroup

    Well I think so we can get the post_type from the acf_form array and use that to change the content for each post type but as to me simple way is to just add a hidden field with post type value and get that in acf/pre_save_post action. I just tried this and its working for me.

    First add the hidden field in acf_from and then get the value

    
    'html_after_fields' => '<div><input type="hidden" name="my_pt" value="u_talez"></div>',
    
    function acf_review_before_save_post($post_id) {
    
    	if (empty($_POST['acf']))
    		return;
    
    	//form 1 
    	$Post_type = $_POST['my_pt'];
    
    	if ( $Post_type == 'cpt' ) {
    		$_POST['acf']['_post_title'] = $_POST['acf']['field_577ba2a05bb33'];
    		$_POST['acf']['_post_content'] = $_POST['acf']['field_577ba2b153bb51'];
    	}
    
    	//form2
    	$Post_type = $_POST['my_pt2'];
    
    	if ( $Post_type == 'pt2' ) {
    		$_POST['acf']['_post_title'] = $_POST['acf']['field_577ba2a05bb33'];
    		$_POST['acf']['_post_content'] = $_POST['acf']['field_577ba2b153bb51'];
    	}	
    
    	return $post_id;
    }
    add_action('acf/pre_save_post', 'acf_review_before_save_post', -1);