Hey there
I’ve been trying to figure out a way of doing this but can’t come up with a solution or see another thread on the forum for this so here I am!
What I’m trying to do is create an ACF checkbox list where you can only select say three of the options in the backend, so something like this
Select three of your favourite fruits;
Apple,
Strawberry,
Orange,
Banana,
Grape,
Peach,
Cheery
Hope that’s clear – this is to limit users in the backend only, front end will just display the three selected fruits
Thank you in advance for your time looking at my problem, any advice, even just pointing me in the right direction of some documentation I might have missed would be hugely welcomed
N
add_filter('acf/validate_value/name=your_field_name', 'only_allow_3', 20, 4);
function only_allow_3($valid, $value, $field, $input) {
if (count($value) > 3) {
$valid = 'Only Select 3';
}
return $valid;
}
https://www.advancedcustomfields.com/resources/acf-validate_value/