php - Update taxonomy field from ACF field when saving post

one text

Solution:

I finally figured it out :

add_action('save_post', '__hp_fuel_type');
function __hp_fuel_type($post_id) {
$fuel_type_acf = !empty($_POST['acf']['field_612cfc339a8ba']) ? $_POST['acf']['field_612cfc339a8ba'] : '';    
if (((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'ΒΕΝΖΙΝΗ') || ((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'UNLEADED')) {
    $fuel_type_acf = '[:el]ΒΕΝΖΙΝΗ[:en]UNLEADED[:]';
}else{if (((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'ΠΕΤΡΕΛΑΙΟ') ||  ((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'DIESEL')) {
    $fuel_type_acf = '[:el]ΠΕΤΡΕΛΑΙΟ[:en]DIESEL[:]';
}else{if (((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'ΑΕΡΙΟ') || ((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'GAS')) {
    $fuel_type_ac = '[:el]ΑΕΡΙΟ[:en]GAS[:]';
}else{if (((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'ΥΒΡΙΔΙΚΟ / ΒΕΝΖΙΝΗ') || ((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'HYBRID / UNLEADED')) {
    $fuel_type_acf = '[:el]ΥΒΡΙΔΙΚΟ / ΒΕΝΖΙΝΗ[:en]HYBRID / UNLEADED[:]';
}else{if (((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'ΥΒΡΙΔΙΚΟ / ΠΕΤΡΕΛΑΙΟ') || ((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'HYBRID / DIESEL')) {
    $fuel_type_acf = '[:el]ΥΒΡΙΔΙΚΟ / ΠΕΤΡΕΛΑΙΟ[:en]HYBRID / DIESEL[:]';
}else{if (((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'ΗΛΕΚΤΡΙΚΟ') ||  ((isset($fuel_type_acf) ? $fuel_type_acf : null) == 'ELECTRIC')) {
    $fuel_type_acf = '[:el]ΗΛΕΚΤΡΙΚΟ[:en]ELECTRIC[:]';}}}}}}
$new_term = wp_insert_term(
    $fuel_type_acf,   // the term 
    'car_fuel_type', // the taxonomy
    array(
        'description' => '',
        'slug'        => strtolower($fuel_type_acf),
    )
);
if(!is_wp_error($new_term)) {
    wp_set_object_terms( $post_id, $new_term['term_id'], 'car_fuel_type' );
} else {
    $term_added = wp_set_object_terms( $post_id, $new_term->error_data['term_exists'], 'car_fuel_type' );
}}

Source