Home Forums ACF PRO acf/update_field not working as expected


acf/update_field not working as expected

  • I want to use the hook acf/update_field/name={field_name} to adjust the formatting on a text input within a repeater before saving the value to the database. My code for this is below.

    function my_theme_remove_non_numeric_characters_from_numeric_populations($value, $post_id, $field) {
        return "Hello world";
    add_action("acf/update_field/name=population", "my_theme_remove_non_numeric_characters_from_numeric_populations", 10, 3);

    Using this action, if my field population is within a repeater, the field always saves as blank. If the my field population is not within a repeater (“top level,” so to speak), the value is saved as normal, but is not affected by my code.

    For the life of me, I can’t figure out what’s going on. Some help would be greatly appreciated.

  • When the field is at the top level if could be a priority issue. Try setting the priority of your filter to 20.

    As for when it is in a repeater field, the reason for this is that the field name is not what you would expect. The field name in this case is constructed using this formula


    More than likely the filter is not being called at all. For the case of this filter and repeater sub fields you need to use the field key rather than the field name. You will need to use the 3rd parameter that is passed to your filter to get other information when needed about the field.

  • Thanks, that helped me track it down. I think my problem was two-fold: I was using acf/update_field/name={field_name}, where it should have been acf/update_value/name={field_name}, and also, as you described, the key was required instead of the name for this repeater field. Thanks much!

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

The topic ‘acf/update_field not working as expected’ is closed to new replies.