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;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.