Home › Forums › Bug Reports › Fields on acf/pre_submit_form does not receive format_values treatment › Reply To: Fields on acf/pre_submit_form does not receive format_values treatment
Yes, I can confirm that ACF is having a hard time loading formatted values in a multi-site field when running during the context of a acf/load_field/name=
.
1. Request starts at main site
2. I have a filter such as: add_filter('acf/load_field/name=schools', function($field) {});
3. Inside the closure of this filter, I run switch_to_blog(3)
and then get_field('state', 'options');
Where state
is a field of type “Select” such as:
ny : New York
fl : Florida
And is configured to return Both (Array)
. But due to a probable issue with ACF, likely at the values
data store, it returns the unformatted value ny
only.
What I had to do was a dirty workaround:
// Pre-load the school state value in the "plugins_loaded" context
add_action('plugins_loaded', function() {
if (!is_not_editing_schools()) {
return;
}
switch_to_blog(3);
global $school_state;
$school_state = get_field('state', 'options'); // ['ny' => 'New York'], as expected
});
add_filter('acf/load_field/name=schools', function($field) {
global $school_state;
// Now I have ['ny' => 'New York'] here, while in this context I was only able to get 'ny' out of get_field after switch_to_blog.
});
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.