Home › Forums › General Issues › Overwrite value of group-field itself (using one of it's sub-fields) › Reply To: Overwrite value of group-field itself (using one of it's sub-fields)
Thanks @hube2 for your quick answer! Actually, I was counting on you 😉
With the field setting I meant a field setting for the acf-field-group
-edit-screen:
add_action("acf/render_field_settings/type=text", [$this, 'render_field_settings'], 9);
The setting:
/**
* Render field settings for multilingual fields
*
* @param Array $field
* @return void
*/
public function render_field_settings( $field ) {
acf_render_field_setting( $field, array(
'label' => __('Multilingual?'),
'instructions' => '',
'name' => 'acfml_multilingual',
'type' => 'true_false',
'ui' => 1,
), false);
}
On the second try, it seems like I made it work. The solution was to hook into acf/update_value
*after* the ACF hook (I used a priority of 12
):
add_filter("acf/format_value/type=group", [$this, 'format_multilingual_value'], 12, 3);
My update_value-function:
/**
* Write the default language's $value to the group $value itself
*
* @param mixed $value
* @param int $post_id
* @param array $field
* @return mixed
*/
public function update_multilingual_value( $value, $post_id, $field ) {
if( !$this->is_acfml_group($field) ) return $value;
$default_language = acfml()->get_default_language();
$value = get_field("{$field['name']}_$default_language", $post_id, false);
return $value;
}
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.