ACF is a very powerful WordPress plugin. Recently I had to control the display of some of the ACF groups conditionally through the code.
I do know that ACF allows to define where to display the meta boxes in WordPress admin but I needed more. I needed to display or hide ACF fields in WordPress admin based on the value of a WordPress option.
Basically, here is the the idea:
- Add a filter to each of the ACF fields the display of which you want to control (using `acf/load_field/<field-name>` filter).
- Control the value of `$field[‘wrapper’][‘class’]` for each of the fields – set it to “hidden” if you want to hide the field.
The solution is not ultimate – the “hidden” field is still there but hidden with the “display” set to “none”.
Also, this will work best if you set the meta box to be seamless. Otherwise, you will see the meta box heading even though the fields are hidden.