How to create a custom method in a PHP class to add a filter to an ACF select field

class MyACFSelectField {

    public function __construct() {
        add_filter('acf/load_field/name=my_select_field', array($this, 'filter_select_options'));
    }

    public function filter_select_options($field) {
        // Modify the options of the select field here
        $field['choices'] = array(
            'option_1' => 'Option 1',
            'option_2' => 'Option 2',
            'option_3' => 'Option 3'
        );

        return $field;
    }
}

new MyACFSelectField();

Leave a Comment

Your email address will not be published. Required fields are marked *