Home › Forums › General Issues › Issue: WPML support: using repeatable fields in option fields
Hi everyone!
I have got a problem using your ACF WPML integration with option pages.
First of all my WPML configuration:
-> Default language: German
-> Available langs : German, English
WPML version: 3.2.7
ACF version: 5.3.1
If I create a new repeatable field for an option page, duplicate the field group for the english language, and insert some rows of data in both languages, the get_field method return different results:
(example configuration:
Option page: example;
Repeatable fields group: slides;
Repeatable fields:
-> name : Text
-> bild : Image
)
page on english mode (not default lang)
[slider_new] => Array
(
[ID] => 427
[key] => field_5615317e1126c
[label] => Slides
[name] => slider_new
[prefix] =>
[type] => repeater
[value] => Array
(
[0] => Array
(
[name] => English
[bild] => Array
(
[ID] => 64
[id] => 64
[title] => *
[filename] => *.jpg
[url] => http://*/wp-content/uploads/2015/09/*.jpg
[alt] =>
[author] => 1
[description] =>
[caption] =>
[name] => *
[date] => 2015-09-28 15:54:33
[modified] => 2015-09-28 15:54:33
[mime_type] => image/jpeg
[type] => image
[icon] => */wp-includes/images/media/default.png
[width] => 500
[height] => 1000
[sizes] => Array
(
[thumbnail] => http://*/wp-content/uploads/2015/09/*-150x150.jpg
[thumbnail-width] => 150
[thumbnail-height] => 150
[medium] => http://*/wp-content/uploads/2015/09/*.jpg
[medium-width] => 150
[medium-height] => 300
[large] => http://*/wp-content/uploads/2015/09/*.jpg
[large-width] => 500
[large-height] => 1000
)
)
)
)
(so the result is the expected one)
site on german (default) mode
[slider_new] => Array
(
[ID] => 427
[key] => field_5615317e1126c
[label] => Slides
[name] => slider_new
[prefix] =>
[type] => repeater
[value] => Array
(
[0] => Array
(
[field_561533ca98ab4] => sfdsf
[field_561533e198ab5] => 202
[name] =>
[bild] =>
)
[1] => Array
(
[field_561533ca98ab4] => deutsch
[field_561533e198ab5] =>
[name] =>
[bild] =>
)
)
[menu_order] => 0
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 426
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => slider_new
[_input] =>
[_valid] => 1
[min] =>
[max] =>
[layout] => table
[button_label] => Add Row
[sub_fields] => Array
(
[0] => Array
(
[ID] => 428
[key] => field_5615317e12227
[label] => Name
[name] => name
[prefix] =>
[type] => text
[value] =>
[menu_order] => 0
[instructions] =>
[required] => 1
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 427
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => name
[_input] =>
[_valid] => 1
[default_value] =>
[placeholder] =>
[prepend] =>
[append] =>
[maxlength] =>
[readonly] => 0
[disabled] => 0
)
[1] => Array
(
[ID] => 429
[key] => field_5615317e122c2
[label] => Bild
[name] => bild
[prefix] =>
[type] => image
[value] =>
[menu_order] => 1
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 427
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => bild
[_input] =>
[_valid] => 1
[return_format] => array
[preview_size] => thumbnail
[library] => all
[min_width] =>
[min_height] =>
[min_size] =>
[max_width] =>
[max_height] =>
[max_size] =>
[mime_types] =>
)
)
)
(so in the default_language version I’ve only access to the ‘field_561533ca98ab4’ like fields and no additional information about the uploaded image)
Output generated using exit(print_r($fields));
one line before ‘return;’ in the get_field_objects method.
Thanks in advance! š
We ran into the exact same problem when using repeater fields in theme options.
I found the culprit, but there is probably not an easy way hook or filter it away. Itās right there in get_fields_objects()
. When ACF saves a theme option in a different language, it appends the language code to the option name, like this:
Default language (German): options_fieldname
Other language (English): options_en_fieldname
The get_fields_objects()
function runs a direct query on the database, with the following SELECT for the default language:
SELECT option_name, option_value FROM wp_options WHERE option_name LIKE 'options_%' OR option_name LIKE '_options_%'
When when we compare it to the query which is run for the English options, we see that is looks explicitly for options with the language code:
SELECT option_name, option_value FROM wp_options WHERE option_name LIKE 'options_en_%' OR option_name LIKE '_options_en_%'
The problem here is, that for the default language, it also matches options with language codes suffixes from other languages. So the English options are loaded as well. ACF then canāt correctly set a value and overwrites the values for the default language with the additionally loaded values from another language.
Now I donāt know how this is solved best. I guess either the query has to be adapted to filter out all other languages or they have to be filtered out after the query.
Some more information to add which is missing in the answer above:
This error only happens when you try to access all options at once using get_fields()
.
Elliot meant that he canāt think of a quick and easy bug fix for this.
However, thereās a workaround, where you donāt use get_fields()
, but get_field()
for every repeater. To still have them all accessible in one place, you can do something like this:
// Put all repeater field names you have in your options fields in an array
$options_repeater_names = array(
'options_repeater_name_1',
'options_repeater_name_2',
'options_repeater_name_3',
);
$options_repeaters = array();
// Loop through repeater field names and use get_field separately for each repeater field
foreach ( $options_repeater_names as $field_name ) {
$options_repeaters[ $field_name ] = get_field( $field_name, 'options' );
}
// Now all the repeaters are accessible in $options_repeaters
Good luck!
The topic ‘Issue: WPML support: using repeatable fields in option fields’ is closed to new replies.
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.