Support

Account

Home Forums General Issues Filter field when saving Reply To: Filter field when saving

  • ACF applies filter only once for each field. It also applies it again with field names, keys and types but that should not be calling your function, but it probably applying the filter on each subfield so that’s where the duplicate is coming from. Instead of being a recursive function it might be better to simply return the original value if the field is a repeater and let the filter handle each subfield. That’s something I hadn’t thought about, should add it to my filter.

    
    add_filter('acf/update_value', 'my_acf_update_value', 10, 3);
    function my_acf_update_value( $value, $post_id=0, $field=array() ) {
      if (isset($field['type']) && ($field['type'] == 'repeater' || $field['type'] == 'flexible_content')) {
        // abort if it's a repeater
        return $value;
      }
    	if (!is_array($value)) {
    		$value .= ' added by filter';
    		return $value;
    	}
    	$return = array();
    	foreach ($value as $index => $data) {
    		$return[$index] = my_acf_update_value ($data);
    	}
    	return $return;
    }