Skip to content

Instantly share code, notes, and snippets.

@gummiforweb
Created January 27, 2018 22:25
Show Gist options
  • Save gummiforweb/07e3cdf2389ced79b9b5406ce483ad29 to your computer and use it in GitHub Desktop.
Save gummiforweb/07e3cdf2389ced79b9b5406ce483ad29 to your computer and use it in GitHub Desktop.
ACF Gallery Field: Pull from default language's images
<?php
add_filter('acf/load_value/type=gallery', 'acf_load_translated_attachment_ids');
function acf_load_translated_attachment_ids($value) {
// if the current language is the default language,
// then we don't need to fetch the translated ids
if (acf_get_setting('default_language') == acf_get_setting('current_language')) {
return $value;
}
// map throught each 'default language' id, and return the translated one
return array_map(function($id) {
return apply_filters('wpml_object_id', $id, 'attachment');
}, $value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment