Home › Forums › ACF PRO › Allow admin to sort a list using Repeater field › Reply To: Allow admin to sort a list using Repeater field
Hi @cfxd
Thanks for the question.
I’m sure this will be possible by hooking into the acf/prepare_field
filter and modifying the sub field’s value / disbaled settings.
Something like this should work:
$GLOBALS['acf_item_count'] = 0;
function acf_prepare_field_item( $field ) {
// set disabled
$field['disabled'] = 1;
// set value
if( empty($field['value']) ) {
// incease count
$GLOBALS['acf_item_count']++;
// set value
$field['value'] = $GLOBALS['acf_item_count'];
}
// return
return $field;
}
add_filter('acf/prepare_field/key=field_5600966e8fad1', 'acf_prepare_field_item', 10, 1);
The only issue is that by setting a select field to ‘disabled’, it won’t save it’s value… perhaps instead, you will need to change the $field['class']
to ‘disabled’, and then add some CSS / JS to prevent the select field from being clicked / changed.
Good luck
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.