Support

Account

Home Forums Feature Requests Consistent Input in Location Field Reply To: Consistent Input in Location Field

  • To answer my own question, I stumbled on the validate_value filter, which allows me to do this. In my case, I simply wanted the input from the location field to include a city and state in the “San Francisco, CA” format, so I accomplished it like this:

    function google_map_acf_validate_value( $valid, $value, $field, $input ) {
    	if ( ! $valid ) { // bail early if it's already invalid
    		return $valid;
    	}
    	
    	preg_match( '/([^,]+), ([A-Z]{2})\b/', $value['address'], $matches );
    	if ( ! $matches ) { // City was not found
    		$valid = 'Address must include city and state';
    	}
    	
    	return $valid;
    }
    add_filter( 'acf/validate_value/type=google_map', 'google_map_acf_validate_value', 10, 4 );