Hello guys,
First of all thanks for reading this thread. So, this is my first time using the load_field and generally a filter in ACF. What I need to achieve is to write a snippet of code which will allow me to filter the User Field Type by returning the Users I want. So I need to basically return specific users. How can I do that?
add_filter('acf/load_field/key=field_583fdadbce3df', 'my_acf_load_value', 10, 3);
function my_acf_load_value( $field ) {
$field['choices'] = array(
'1' => 'Tzio'
);
return $field;
}
Actually, in this case, what you’re looking for is the acf/fields/user/query hook/filter. This hook is undocumented at the moment but it works the same way as acf/fields/relationship/query https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/. The main difference is that the arguments you return should be the arguments that you’d use for the WP function get_users() https://codex.wordpress.org/Function_Reference/get_users
I just stumbled across this thread and am having the same issue. I am trying to limit the amount of users able to be selected. The relationship field allows a maximum posts value but the users field doesn’t seem to have this option.
@appnet Use an acf/validate_value filter similar to what I suggested here https://support.advancedcustomfields.com/forums/topic/check-number-when-saving/
There may be a way to do this by altering the select2 arguments, see the select2_init
section. Unfortunately, I don’t know if this is possible or how to do so if it is.
Beyond this it would take the developer adding this feature. You can request this by submitting a new ticket here https://support.advancedcustomfields.com/new-ticket/