Home › Forums › Front-end Issues › Frontend form for new post not saving taxonomy terms › Reply To: Frontend form for new post not saving taxonomy terms
Sure! I’m not using the exact code above, just a similar method. Here is the php code i’m using to display the form as well as the custom function.
The below code works to manually save the taxonomies, but if I remove that portion of the function the taxonomies don’t save.
NOTE: I have the taxonomy field set to NOT save to the post at the moment just in case it interfered with me doing manually. But when troubleshooting, I had it turned on.
Also note, there are fields called “columns” which are reliant on another plugin. They just change the layout of the fields and are not important to the actual content of the form.
On page template:
<div id="new-audition-form" class="hide-submit">
<?php
$new_audition = array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'audition',
'post_status' => 'draft',
),
'post_title' => true,
'post_content' => true,
'submit_value' => 'Continue >',
'return' => '%post_url%',
);
acf_form($new_audition);
?>
</div>
Function:
//ACF Front-End Audition Functions
//Redirect to the terms and conditions page on the first post save
function tps_acf_save_audition( $post_id ) {
if (!is_admin()) {
// manually update the audition_type taxonomy field
$term_object = get_term($_POST['acf']['field_5701d3e794a6f'], 'audition_type');
$term_slug = $term_object->slug;
wp_set_object_terms($post_id, $term_slug, 'audition_type');
if (get_post_status($post_id) == 'draft') {
wp_redirect(get_bloginfo('url').'/auditions/terms-and-conditions?auditionid='.$post_id);
exit;
}
}
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'tps_acf_save_audition', 20);
After the user is redirected to the terms and conditions page, they press a button that publishes the post, completing the process.
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.