Support

Account

Home Forums Front-end Issues Taxonomies are not saved via the frontend. But it works in the backend. Why? Reply To: Taxonomies are not saved via the frontend. But it works in the backend. Why?

  • And once again I answer myself 😉
    I forgot the $post_id inside the acf-field. This is how it works perfectly:

    function update_post_taxonomy( $post_id ) {
    $myfield = get_field('my_field_name', $post_id);
    if( $myfield ) {
    wp_set_object_terms($post_id, 'myterm', 'mytaxonomy', true);
    } else if ( empty( $myfield ) ) { 
    wp_remove_object_terms( $post_id, 'myterm', 'mytaxonomy', true );
    }
    }
    add_action( 'acf/save_post', 'update_post_taxonomy', 10 );