Home › Forums › Feature Requests › Option to trim custom field › Reply To: Option to trim custom field
Sorry for replying to a 2 year old post. I agree that trimming fields should be included in the plugin. But the code posted by Radovan didn’t worked for me, since I also have checkboxes (in the end the ACF values aren’t strings but an array, and former code fails).
Here is a slightly improved code for anyone stumbling on this page
function trim_acf_fields( $post_id )
{
// load from post
if( isset($_POST['fields']) ) {
foreach($_POST['fields'] as $key => $value) {
if(!is_array($value))
$_POST['fields'][$key] = trim($value);
}
}
}
// run before ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'trim_acf_fields', 1);
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.