Support

Account

Home Forums General Issues Need help for auto-increment field with update_field Reply To: Need help for auto-increment field with update_field

  • Thank you very much for your leads, I found a solution that seems to work well :

    add_option('ebo_dernier_num_club','3005','','no');
    function ebo_renseigne_num_affiliation($value, $post_id, $field) {
    	if (! $value && get_post_type($post_id)=='club_type') {
    		$last_num = (int) get_option('ebo_dernier_num_club', '3000');
    		$last_num++;
    		update_option('ebo_dernier_num_club', $last_num);
    		$value = $last_num;
    	}
    	return $value;
    }
    add_filter('acf/update_value/name=numero_affiliation', 'ebo_renseigne_num_affiliation', 10, 3);
    

    I also wanted to make the field uneditable with this function:

    function msk_acf_disable_field($field) {
        $field['disabled'] = true;    
        return $field;
    }
    add_filter('acf/load_field/name=numero_affiliation', 'msk_acf_disable_field');

    But that does not seem to be compatible.