Home › Forums › Add-ons › Repeater Field › Repeater field value in acf/update_value filter › Reply To: Repeater field value in acf/update_value filter
Thanks for your answer!!
What I need is to sync the data of an option page between multiple language, using WPML.
– In a plugin
– Option page created via php by the plugin (acf_add_options_page, acf_add_local_field,etc)
– When the user save the form in any language in the admin, I need the same data to be in the form when the user switch language. These are settings shared for all languages.
Best approach I found was to watch for the save and then resave the data in all languages. Maybe there’s a better way…
If not, here’s my code to do it. It works fine for all the fields, except one repeater)
$henri_fields_to_sync = array(
"henri_google_analytics",
"henri_remove_accent",
"henri_disable_update",
"henri_password_protect",
"henri_social_icons_group",
);
if ( isset( $_SESSION['is_saving_acf_henri'] ) ) {
unset( $_SESSION['is_saving_acf_henri'] );
}
/** Sync acf_field between language */
function henri_sync_acf_field_language( $fieldValue, $field, $post_id ) {
if ( ! isset( $_SESSION ) ) {
session_start();
}
global $sitepress;
if ( !isset( $sitepress ) ) {
return;
}
if ( ! isset( $_SESSION['is_saving_acf_henri'] ) ) {
$_SESSION['is_saving_acf_henri'] = true;
$activeLang = $sitepress->get_ls_languages();
foreach ( $activeLang as $key => $value ) {
if ( $key !== ICL_LANGUAGE_CODE ) {
set_global_option_icl( $post_id['name'], $fieldValue, $key );
}
}
unset( $_SESSION['is_saving_acf_henri'] );
}
return $fieldValue;
}
foreach ( $henri_fields_to_sync as $henri_field_to_sync ):
add_filter( 'acf/update_value/name=' . $henri_field_to_sync, 'henri_sync_acf_field_language', 10, 3 );
endforeach;
Thanks again for your time!
stef
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.