Support

Account

Home Forums Add-ons Repeater Field Passing extra parameters in acf/load_value

Solving

Passing extra parameters in acf/load_value

  • I’m using a kind of nested acf/load_value hook to loop through the subfields of a repeater with the intension of modifying the values. But for my purpose I want access to the parent field name from within the subfield filter action without the need to set globals.

    function repeater_load_value( $value, $post_id, $field ) {
        
        $sub_fields = $field['sub_fields'];
    
        function sub_field_load_value( $sub_field_value, $post_id, $sub_field ) {
            
            // *** This is where I'd like access to the parent field name ****
            
            return $sub_field_value;
        }
        
        foreach ( $sub_fields as $sub_field ) {
            
            add_filter( 'acf/load_value/key='.$sub_field['key'], 'sub_field_load_value', 10, 3);
        }
        
        return $value;
    }
    
    add_filter( 'acf/load_value/name=my_repeater_name', 'repeater_load_value', 10, 3);

    I thought of using an anonymous function when adding the acf/load_value filter for the subfields and passing the parent field name through as a parameter but there is still a scope issue.

    Any suggestions?

  • Hi,
    i am not sure but i think you can access the parent name inside your repeater_load_value(); with $field['name']; maybe store that in a variable and pass it as a param to the sub_field_load_value()

  • Hi, was this ever resolved? Im looking at a similar requirement where I need to loop through all repeater fields to modifiy a specific fields value.

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

You must be logged in to reply to this topic.