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);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.