Home › Forums › Front-end Issues › Selecting Category from Frontend Form › Reply To: Selecting Category from Frontend Form
I use this code in my template
<?php acf_form(array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => '',
'post_status'=> 'publish',
'post_title' => $_POST['acf']['field_5882557e92006'].' - '.$_POST['acf']['field_5882557e9207c'].' - '.get_cat_name( $_POST['acf']['field_588713c7a61d9'] ), // Post Title ACF field key
'post_category' => $_POST['acf']['field_588713c7a61d9'], // Post Category ACF field key
),
'field_groups' => array(98), // Create post field group ID(s)
'form' => true,
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Submit Post',
'updated_message' => 'Saved!',
'uploader' => 'wp',
'return' => '/'
)); ?>
…and that in my function.php
function acf_review_before_save_post($post_id) {
if (empty($_POST['acf']))
return;
$_POST['acf']['_post_title'] = get_cat_name( $_POST['acf']['field_588713c7a61d9'] ).' - '.$_POST['acf']['field_5882557e92006'].' - '.$_POST['acf']['field_5882557e9207c'];
$_POST['acf']['_post_category'] = $_POST['acf']['field_588713c7a61d9'];
return $post_id;
}
add_action('acf/pre_save_post', 'acf_review_before_save_post', -1);
?>
…and all work very well except for the _post_category.
I whant to change the real category of the post but it dosen’t change after saving.
What am I wrong?
Thanks!
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.