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
Narrowing it down here…
The problem is in the use of acf/save_post.
Quick overview: I have a multi-step process setup for creating a tribute (custom post type). First form creates the post (a custom post type). Next forms are for adding additional meta data. To get users to step 2, I am using the acf/save_post action to redirect them (back to the editor) after the post is created. However, using this action is preventing the custom taxonomy (states) from saving. It saves the text fields just fine.
function get_tribute_editor_url($trib_step=false,$trib_id=false) {
$url = site_url() . '/edit-tribute/';
if ($trib_step && $trib_id) {
$url .= "?trib_step=$trib_step&trib_id=$trib_id";
}
return $url;
}
function acf_post_save_tribute( $post_id ) {
// bail early if not a tribute
if( get_post_type($post_id) !== 'tribute' ) {
return;
}
// get step
$trib_step = get_field('trib_step', $post_id);
// create/update the post title if this is a new post or if the user has edited step 1
if ( $trib_step <= 1 ) {
$args = array(
'ID' => $post_id,
'post_title' => $_POST['acf']['field_558884854c6ce'] . ' ' . $_POST['acf']['field_558884974c6cf'],
);
wp_update_post($args);
}
// redirect new tributes to step 2 and pass along the proper ID
if ($trib_step < 1) {
$redirect = get_tribute_editor_url(2,$post_id);
wp_redirect($redirect);
exit;
}
}
add_action( 'acf/save_post', 'acf_post_save_tribute', 20);
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.