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) {
            $_POST['fields'][$key] = trim($value);
    // run before ACF saves the $_POST['fields'] data
    add_action('acf/save_post', 'trim_acf_fields', 1);