Support

Account

Home Forums General Issues Using the same filter (function) for multiple fields

Helping

Using the same filter (function) for multiple fields

  • On another thread I talked about substituting labels for images using my_acf_load_field.

    However I just noticed that I can’t use my_acf_load_field for multiple radio fields. What I mean is that I have two different radio fields where I wanted the labels to be replaced by images. But my_acf_load_field seems to only let me use it for one of the fields. It will read from both, but it will put all values in the first field.

    This is almost certainly a php coding thing rather than a ACF specific thing, but still wanted to ask. In the code I put below, it will return all images, but it puts all labels in both radio fields. I tried to load my_acf_load_field twice, but that was an obvious fail since I’m declaring the same function twice.
    Any workarounds would be appreciated.

    function my_acf_load_field( $field ) {
    
        $field['choices'] = array(
            'Learn' => '<img src="http://lifeflow.io/wp-content/uploads/2018/03/LifeFlow-Toddlers.svg" alt="image" width="150" height="150" class="image_cl" /><p>Learn</p>
    ',
            'Pet' => '<img src="http://lifeflow.io/wp-content/uploads/2018/03/LifeFlow_Other_Learning_Typesv3.svg" alt="image" width="150" height="150" class="image_cl" /><p>Pet</p>
    ',
             'Dog' => '<img src="http://lifeflow.io/wp-content/uploads/2018/03/LifeFlowDogMainpg-1.svg" alt="image" width="150" height="150" class="image_cl" /><p>Dog</p>,
    ',
            'Cat' => '<img src="http://lifeflow.io/wp-content/uploads/LifeFlow_Pets.svg" alt="image" width="150" height="150" class="image_cl" /><p>Cat</>
    '
            
        );
    
        return $field;
    }
    
    add_filter('acf/load_field/name=path_type', 'my_acf_load_field');
    add_filter('acf/load_field/name=pet_types', 'my_acf_load_field');
  • Note that “filter for every field” didn’t seem to work either.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Using the same filter (function) for multiple fields’ is closed to new replies.