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

  • I’m not sure if this is THE solution. I’d absolutely love to NOT have to manually update the Taxonomy, but have ACF handle it – like it seems it should do? Totally may be user error for why it’s not.

    I’m manually saving the taxonomy using wp_set_object_terms(). In this case the user is restricted to selecting a single term. The solution would look a bit different if multiple terms were allowed.

    function acf_post_save_tribute( $post_id ) {
    	// bail early if not a tribute
    	if( get_post_type($post_id) !== 'tribute' ) {
    	// bail early if wordpress admin
    	if( is_admin() ) {
    	// 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'],
    		// manually update the state taxonomy field
    		$the_term_obj = get_term($_POST['acf']['field_5591b6e43e1b7'], 'trib_state');
    		$the_term_slug = $the_term_obj->slug;
    		wp_set_object_terms($post_id, $the_term_slug, 'trib_state');
    	// redirect new tributes to step 2 and pass along the proper ID
    	if ($trib_step < 1) {
    		$redirect = get_tribute_editor_url(2,$post_id);