Thanks, John, for your help on this. There’s no redundancy and saving a post goes much faster.
Thanks!
Tim
Thanks for the recursive example–it was just what I needed. Here’s what I came up with that works with non-repeater fields and repeater subfields:
add_filter('acf/update_value', 'my_acf_update_value', 10, 3);
function my_acf_update_value( $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;
}
There’s still something not quite right as ‘ added by filter’ appears twice on the 2 repeater subfields and saving the page is appallingly slow even on my local server. For my purposes (removing cruft from pasting text from MS Word), I can tolerate running the filter twice, but I’d like to cut the redundancy if I can. Any suggestions?
I very well understand the futility of filtering–just call me Sisyphus.
I’m making progress–I decided to simplify, and wrote this code that works on a page with a non-repeater ACF field:
add_filter('acf/update_value', 'my_acf_update_value', 10, 3);
function my_acf_update_value( $value, $post_id, $field ) {
$value .= ' added by filter';
return $value;
}
Then I tried on a page with an ACF repeater–>crash with “Warning: Invalid argument supplied for foreach() in … /plugins/advanced-custom-fields-pro/pro/fields/repeater.php on line 722”
Can you point me towards how to make this work for both single fields and repeater subfields?
Thanks!