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 );
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.