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.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.